import java.awt.* ; import java.awt.event.* ; import javax.swing.* ; import javax.swing.border.* ; class TerminationListener implements WindowListener { public void windowActivated(WindowEvent e) {} public void windowClosed(WindowEvent e) {} public void windowClosing(WindowEvent e) { System.exit(0) ; } public void windowDeactivated(WindowEvent e) {} public void windowDeiconified(WindowEvent e) {} public void windowIconified(WindowEvent e) {} public void windowOpened(WindowEvent e) {} } class LabelPanel extends JPanel { public LabelPanel() { JButton redButton = new JButton("Red") ; JButton blueButton = new JButton("Blue") ; JButton greenButton = new JButton("Green") ; JPanel buttons = new JPanel() ; buttons.add(redButton) ; buttons.add(blueButton) ; buttons.add(greenButton) ; Border border = BorderFactory.createEtchedBorder() ; buttons.setBorder(border) ; JLabel label = new JLabel("A Bunch of Buttons") ; label.setAlignmentX(0.5F) ; //label.setAlignmentX(1F) ; Box box = Box.createVerticalBox() ; box.add(label) ; box.add(buttons) ; add(box) ; } } public class LabelTest { public static void main(String [] args) { JFrame frame = new JFrame() ; frame.setTitle("LabelTest") ; frame.setSize(450, 300) ; frame.addWindowListener(new TerminationListener()) ; frame.getContentPane().add(new LabelPanel()) ; frame.setVisible(true) ; } }