/* SimplePanelExample * This example contains three flow layout panels arranged in a frame. * Each panel is contained in a grid layout 3 rows deep by 1 column * wide. Each of the rows are indentified by a single label component. */ import java.awt.*; import javax.swing.*; public class SimplePanelExample extends JFrame { // Panel 1 JPanel row1 = new JPanel(); // Initialize components here such as buttons, labels, ect. JLabel lbl1 = new JLabel("This is row 1"); // Panel 2 JPanel row2 = new JPanel(); JLabel lbl2 = new JLabel("This is row 2"); // Panel 3 JPanel row3 = new JPanel(); JLabel lbl3 = new JLabel("This is row 3"); // Constructor for SimplePanelExample class public SimplePanelExample(){ super("Simple Panel Example"); setSize(600, 600); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // The frameLayout that will contain the panels // This grid frameLayout will be 3 row by 1 column GridLayout frameLayout = new GridLayout(3,1); setLayout(frameLayout); // Defines the frameLayout of this container ///////////////// Row 1 ////////////////////// FlowLayout layoutRow1 = new FlowLayout(FlowLayout.CENTER); // This flow layout will center the components row1.setLayout(layoutRow1); // Defines the frameLayout of this panel. row1.add(lbl1); add(row1); //////////////// Row 2 ///////////////////////// FlowLayout layoutRow2 = new FlowLayout(FlowLayout.LEFT); row2.setLayout(layoutRow2); // Defines the frameLayout of this panel. row2.add(lbl2); add(row2); //////////////// Row 3 ///////////////////////// FlowLayout layoutRow3 = new FlowLayout(FlowLayout.RIGHT); row3.setLayout(layoutRow3); // Defines the frameLayout of this panel. row3.add(lbl3); add(row3); setVisible(true); } public static void main(String[] arguments) { //Crates an instance of the frame SimplePanelExample myFrameSetup = new SimplePanelExample(); } }