Sunday, March 13, 2005

Writing the createContentPane method

Program

    void createContentPane() {
        JPanel jPanelCenter = new JPanel();
        jPanelCenter.setLayout(new BorderLayout());
        jPanelCenter.add(createStatusBar(), BorderLayout.SOUTH);

        getContentPane().add(jPanelCenter, BorderLayout.CENTER);
    }

jPanelCenter is placed at the center of the ContentPane because SOUTH, EAST, WEST, NORTH are reserved for jToolBar1.

Example
    void createContentPane() {
        JPanel jPanelCenter = new JPanel();
        jPanelCenter.setLayout(new BorderLayout());
        jPanelCenter.add("North", new JButton("North"));
        jPanelCenter.add("South", new JButton("South"));
        jPanelCenter.add("East", new JButton("East"));
        jPanelCenter.add("West", new JButton("West"));
        jPanelCenter.add("Center", new JButton("Center"));

        getContentPane().add(jPanelCenter, BorderLayout.CENTER);
    }

No comments: