// Example of a hierarchical layout import javax.swing.*; import java.awt.event.*; import java.awt.*; public class Hierarchies extends JFrame { // The panel into which we draw things class DrawingPanel extends JPanel { DrawingPanel() { setPreferredSize( new Dimension( 400, 200 ) ); } protected void paintComponent(Graphics g) { super.paintComponent(g); g.setColor( Color.RED ); g.fillOval( 10, 10, getWidth()-20, getHeight()-20 ); } } // The constructor for this JFrame Hierarchies() { super(); // A panel for all the buttons JPanel buttonPanel = new JPanel(); buttonPanel.setLayout( new FlowLayout() ); for (int i=0; i<10; i++) { JButton button = new JButton( "button " + i ); buttonPanel.add( button ); } // A panel for drawing DrawingPanel drawingPanel = new DrawingPanel(); // The JFrame Container cp = getContentPane(); cp.setLayout( new BorderLayout() ); cp.add( drawingPanel, BorderLayout.CENTER ); cp.add( buttonPanel, BorderLayout.SOUTH ); pack(); requestFocus(); setVisible(true); } // Test program public static void main( String [] args ) { Hierarchies hier = new Hierarchies(); } }