Laying Out Components in a Row or Column : BoxLayout « Swing JFC « Java






Laying Out Components in a Row or Column

  

import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;

public class Main {
  public static void main(String[] argv) throws Exception {
    JButton component1 = new JButton();
    JButton component2 = new JButton();

    Box box = new Box(BoxLayout.X_AXIS);

    box = Box.createHorizontalBox();

    // Add components
    box.add(component1);
    box.add(component2);

  }
}

   
    
  








Related examples in the same category

1.Separating Components in a Row or Column
2.Glue spreads the components as far apart as possible.
3.Strut spreads the components apart by a fixed distance
4.A vertical box container arranges the components top-to-bottom aligned in their preferred sizes.
5.BoxLayout puts components into a row or into a column
6.BoxLayout: set a rigid area among our components.
7.Align your components in horizontal or vertical layout