import javax.swing.*; import java.awt.*; import java.awt.event.*; public class MyLayout2 { private static void addCenteredButton (String text, Container container) { JButton button = new JButton (text); button.setAlignmentX (Component.CENTER_ALIGNMENT); container.add (button); } public static void main (String[] args) { JFrame frame = new JFrame ("Program"); Container contentPane = frame.getContentPane (); contentPane.setLayout (new BorderLayout ()); // not necessary JPanel westPanel = new JPanel (); westPanel.setLayout (new GridLayout (0,3, 10,10)); for (int i=0 ; i<9 ; i++ ) westPanel.add (new JButton (String.valueOf (i+1))); contentPane.add (westPanel, BorderLayout.WEST); JPanel centerPanel = new JPanel (); centerPanel.setLayout (new BorderLayout ()); centerPanel.add (new JButton ("Up"), BorderLayout.NORTH); centerPanel.add (new JButton ("Down"), BorderLayout.SOUTH); JPanel ccPanel = new JPanel (); ccPanel.setLayout (new FlowLayout ()); ccPanel.add (new JButton ("Go")); ccPanel.add (new JButton ("with")); ccPanel.add (Box.createRigidArea (new Dimension (10,10))); ccPanel.add (new JButton ("the")); ccPanel.add (new JButton ("flow")); centerPanel.add (ccPanel, BorderLayout.CENTER); contentPane.add (centerPanel, BorderLayout.CENTER); JPanel eastPanel = new JPanel (); eastPanel.setLayout (new BoxLayout (eastPanel, BoxLayout.Y_AXIS)); addCenteredButton ("Nina", eastPanel); addCenteredButton ("Pinta", eastPanel); eastPanel.add (Box.createVerticalGlue ()); addCenteredButton ("Santa Maria", eastPanel); contentPane.add (eastPanel, BorderLayout.EAST); frame.addWindowListener (new WindowAdapter() { public void windowClosing (WindowEvent e) { System.exit(0); } }); frame.pack (); frame.setVisible(true); } }