Mega Code Archive

 
Categories / Java / Swing JFC
 

A test of the BoxLayout manager using the Box utility class

/* Java Swing, 2nd Edition By Marc Loy, Robert Eckstein, Dave Wood, James Elliott, Brian Cole ISBN: 0-596-00408-7 Publisher: O'Reilly  */ // HBox.java //A quick test of the BoxLayout manager using the Box utility class. // import java.awt.Button; import java.awt.Panel; import javax.swing.BoxLayout; import javax.swing.JFrame; public class HBox extends JFrame {   public HBox() {     super("Horizontal Box Test Frame");     setSize(200, 100);     Panel box = new Panel();     // Use BoxLayout.Y_AXIS below if you want a vertical box     box.setLayout(new BoxLayout(box, BoxLayout.X_AXIS));     setContentPane(box);     for (int i = 0; i < 3; i++) {       Button b = new Button("B" + i);       box.add(b);     }     setDefaultCloseOperation(EXIT_ON_CLOSE);     setVisible(true);   }   public static void main(String args[]) {     HBox bt = new HBox();   } }