We need you!

We're working hard on the next version of Developer Fusion. Let us know what you think we should be up to!

Members

Technology Zones

Articles

Hosted By

MaximumASP

Info

Rated
Read 24,870 times

Contents

Related Categories

Programming with Swing - Component Layout

Michael H

Component Layout

You may wonder what purpose having to add components to a JPanel serves. JPanels provide the means to layout your components. You choose the layout manager in the constructor for the JPanel. The most common Layouts are:

  • FlowLayout
  • BorderLayout
  • BoxLayout
  • GridLayout
  • GridBagLayout

The following does not describe the full use of all the layout managers and should not be considered the final word on layout managers. I only describe the first
two which are the easiest to use.

The code needed to use a layout manager is like so:

JPanel pane = new JPanel( new BorderLayout() );

and then to add a control to the JPanel:

pane.add(button1, BorderLayout.CENTER);  // possibilities are: NORTH, EAST, WEST, CENTER, SOUTH

And that is how to use BorderLayout. To use FlowLayout is easy as it is the default and you have been using it without even realizing it when we were learning to add components. To learn how to use the other layout managers go get the great book: Java Foundation Classes In A Nutshell.

Comments

  • Closing button on internal frame

    Posted by manojacharya on 14 Nov 2005

    Hello,
    I want to add a closing button to the internal frame. I am not able to do it. Plz help.javascript:smilie(':confused:')
    confused

  • Java - MDI - ChildFrames

    Posted by BG3000 on 28 Oct 2004

    Hi.

    I have an ChildFrame inside of an DesktopFrame. I want to insert a JButton into the ChildFrame. But this JButton turns out to be very tiny in that child frame. If I maximize the child frame, t...

  • Posted by munas on 13 Sep 2004

    jho....

    just call your child frames as follows

    public class MainFrame extends JFrame
    {
    ChildFrame1 child1;
    public MainFrame()
    {
    final JDesktopPane desktop = new JDesktopPane();
    ...

  • JAVA MDI

    Posted by jho on 05 Aug 2004

    i have a JFrame named MainFrame which also uses JDesktoPane. I created 2 JInternalFrame class named ChildFrame1 and ChildFrame2. When I can click the menu on the mainframe, it shows the childframe1. I...