Layout ManagersTopGUI ComponentsContainers


Both JPanel and the object obtained by sending getContentPane() to a WindowController object are containers (and have type Container). The following methods are available for all containers. To define the type of layout, use:

    void setLayout (LayoutManager lm)
LayoutManager may be any of the layout managers listed below.

To add something to a container:

    void add (Component c)
Component may be any Component (such as JButton, JTextField, JSlider, ...) or Container (such as JPanel). Use the method above if the container has a FlowLayout or GridLayout. Use the one below if it has a BorderLayout.
    void add (Component c, int position)
The position may be any of BorderLayout.NORTH, BorderLayout.SOUTH, BorderLayout.EAST,
BorderLayout.WEST, or BorderLayout.CENTER.

Construct a JPanel with new JPanel ()

Layout ManagersTopGUI ComponentsContainers