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(); } }