wood burning stoves 2.0
The moose likes Swing / AWT / SWT and the fly likes BorderLayout problem with NullLayout Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "BorderLayout problem with NullLayout" Watch "BorderLayout problem with NullLayout" New topic

BorderLayout problem with NullLayout

sreenath reddy
Ranch Hand

Joined: Sep 21, 2003
Posts: 415

I am having a JPanel which is using BorderLayout and i am adding a Panel and Label at the BorderLayout.south and North ....But the Panel is not visible . I am using NullLayout for that Panel ...

Can any one let me know whats the reason and i can't prevent the inner panel to have null layout

Here is how my code looks like

final JPanel panel = new JPanel();
panel.setLayout(new BorderLayout());

final JPanel panel1 = new JPanel();
final JLabel label = new JLabel("sdas");
label.setPreferredSize(new Dimension(10, 22));

JButton button = new JButton("Click here");
button.setBounds(new Rectangle(25,10, 20 , 20 ));

panel.add(panel1, BorderLayout.NORTH);
panel.add(label, BorderLayout.SOUTH);

But the same works fine if i set someother layout than Null Layout
Paul Clapham

Joined: Oct 14, 2005
Posts: 19973

When you use NullLayout for a panel, don't you have to specify the exact location of each component you add to that panel?
sreenath reddy
Ranch Hand

Joined: Sep 21, 2003
Posts: 415
I have specified the exact location by saying button.setBounds(new Rectangle(x,y,width,height)) . Button is added to the panel with null layout
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15302

Moving to the Swing forum...

GenRocket - Experts at Building Test Data
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
panel1 has no size, add this line

panel1.setPreferredSize(new Dimension(200,100));
I agree. Here's the link: http://aspose.com/file-tools
subject: BorderLayout problem with NullLayout
jQuery in Action, 3rd edition