The Java Developers Almanac 1.4


Order this book from Amazon.

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

e850. Laying Out Components in a Row or Column

A horizontal box container arranges the components left-to-right in their preferred sizes. The row of components are vertically centered.
    // Create horizontal box container
    Box box = new Box(BoxLayout.X_AXIS);
    
    // Here is a another way to create a horizontal box container
    box = Box.createHorizontalBox();
    
    // Add components
    box.add(component1);
    box.add(component2);
A vertical box container arranges the components top-to-bottom aligned in their preferred sizes. The column of components are left-aligned.
    // Create vertical box container
    box = new Box(BoxLayout.Y_AXIS);
    
    // Here is a another way to create a vertical box container
    box = Box.createVerticalBox();
    
    // Add components
    box.add(component1);
    box.add(component2);

 Related Examples
e851. Separating Components in a Row or Column
e852. Laying Out Components in a Flow (Left-to-Right, Top-to-Bottom)
e853. Laying Out Components in a Grid
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.