The Java Developers Almanac 1.4


Order this book from Amazon.

   
Home > List of Packages > javax.swing  [141 examples] > Layout  [5 examples]

e853. Laying Out Components in a Grid

When components are added to the container, they fill the grid left-to-right, top-to-bottom.
    int rows = 2;
    int cols = 2;
    JPanel panel = new JPanel(new GridLayout(rows, cols));
    panel.add(component1);
    panel.add(component2);

 Related Examples
e850. Laying Out Components in a Row or Column
e851. Separating Components in a Row or Column
e852. Laying Out Components in a Flow (Left-to-Right, Top-to-Bottom)
e854. Laying Out Components Using Absolute Coordinates

See also: Actions    JButton    JCheckBox    JComboBox    JDesktop and JInternalFrame    JFrame, JWindow, JDialog    JLabel    JList    JProgressBar    JRadioButton    JScrollPane    JSlider    JSpinner    JSplitPane    JTabbedPane    JToolBar    Keystrokes and Input Maps    Look and Feel    Menus    Progress Monitor    The Screen    Tool Tips    UI Default Values   


© 2002 Addison-Wesley.