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);
}
}
----------------------------------
> 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