Mega Code Archive

 
Categories / Java Tutorial / Swing
 

Separating 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.add(component1);     box.add(Box.createGlue());     box.add(component2);   } }