Strut spreads the components apart by a fixed distance : BoxLayout « Swing JFC « Java






Strut spreads the components apart by a fixed distance

  

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

    Box box = new Box(BoxLayout.X_AXIS);
    int width = 10;
    box.add(Box.createHorizontalStrut(width));
    box.add(component1);

  }
}

   
    
  








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.Laying Out Components in a Row or Column
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