Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / January 2007

Tip: Looking for answers? Try searching our database.

Container Question. Please help!!! Thanks!!!

Thread view: 
gg - 18 Jan 2007 03:27 GMT
How come this...
----------------------------------
public class MainFrame extends JFrame {
    private JPanel panelOne;

    public MainFrame() {
        JLabel aLabel = new JLabel("A Label");

        panelOne = new JPanel(new FlowLayout(FlowLayout.CENTER));
        panelOne.add(aLabel);

        this.setLayout(new BorderLayout());
        this.add(panelOne, BorderLayout.NORTH);

        this.setSize(500, 500);
        this.setVisible(true);
    }
}
----------------------------------
Work just as well, what is the container for, it seems to work without
it. Any problems if I don’t use it. Thank you for you help.

public class MainFrame extends JFrame {
    private JPanel panelOne;

    public MainFrame() {
        JLabel aLabel = new JLabel("Label!!!");

        panelOne = new JPanel(new FlowLayout(FlowLayout.CENTER));
        panelOne.add(aLabel);

        Container container = this.getContentPane();
        container.setLayout(new BorderLayout());
        container.add(panelOne, BorderLayout.NORTH);

        this.setSize(500, 500);
        this.setVisible(true);
    }
}
----------------------------------
Thomas Fritsch - 24 Jan 2007 12:32 GMT
> How come this...
> ----------------------------------
> public class MainFrame extends JFrame {
[...]
>          this.setLayout(new BorderLayout());
>          this.add(panelOne, BorderLayout.NORTH);
[...]
> ----------------------------------
> Work just as well, what is the container for, it seems to work without
> it. Any problems if I don?t use it. Thank you for you help.
>
> public class MainFrame extends JFrame {
[...]
>          Container container = this.getContentPane();
>          container.setLayout(new BorderLayout());
>          container.add(panelOne, BorderLayout.NORTH);
[...]
> ----------------------------------

It was a difference until Java 1.4 (only the second variant did work).
It is no difference since Java 1.5 (both variants work).

See <http://java.sun.com/j2se/1.5.0/docs/guide/swing/1.5/index.html> (look
for 4753342) and
<http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4753342>

Signature

Thomas



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.