Is this your first time here? SwingWiki is a Java Swing Developer community site with an big archive of Swing-related usenet groups and mailing lists, but also tips, tricks and articles and book reviews written by your colleagues from around the world. If you came here through a search engine and did not find what you were looking for, make sure to check the wiki table of contents.

FlowLayout hides content

If there is not enough space for everything, FlowLayout hides some components. To avoid that, use GridLayout (0,numColumns,xMargin,yMargin) instead of FlowLayout. This will resize all components to fit on the screen. However, the downside is that all of them will be the same size (because each cell in GridLayout has equal size).

Compare the effect of the following two samples to decide wether to use this trick.

import javax.swing.*;
import java.awt.*;
 
public class FlowLayoutDemo {
  public static void main(String[] args) {
    JFrame fr=new JFrame("Flow Layout Demo");
    fr.setDefaultCloseOperation(fr.EXIT_ON_CLOSE);
 
    fr.setSize(500,80);
    Container content=new JPanel();
    //content.setLayout(new GridLayout(0,4,5,5));
    fr.setContentPane(content);
    for (int i=0; i<10; i++) 
        content.add(new JButton("Button #"+i));
    fr.show();		
  }
}

 
import javax.swing.*;
import java.awt.*;
 
public class GridLayoutDemo {
  public static void main(String[] args) {
    JFrame fr=new JFrame("Grid Layout Demo");
    fr.setDefaultCloseOperation(fr.EXIT_ON_CLOSE);
    fr.setSize(500,80);
    Container content=new JPanel();
    content.setLayout(new GridLayout(0,4,5,5));
    fr.setContentPane(content);
    for (int i=0; i<10; i++) 
        content.add(new JButton("Button #"+i));
    fr.show();		
  }
}
 

Comments? Corrections? Contact us or Login to edit pages directly (registration is free and takes less than displaying a JLabel)
  workaround/flowlayout_hides_content.txt · Last modified: 2005/12/17 16:59 by 83.67.205.204 (gojko)
 
Recent changes | RSS changes | Table of contents | News Archive | Terms And Conditions | Register | The Quest For Software++| Ruby Resources

Sedo - Buy and Sell Domain Names and Websites project info: swingwiki.org Statistics for project swingwiki.org etracker� web controlling instead of log file analysis