Mega Code Archive

 
Categories / Java Tutorial / Swing
 

A vertical box container arranges the components top-to-bottom aligned in their preferred sizes

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();     // Create vertical box container     Box box = new Box(BoxLayout.Y_AXIS);     // create a vertical box container     box = Box.createVerticalBox();     // Add components     box.add(component1);     box.add(component2);   } }