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