• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

BorderLayout problem with NullLayout

 
Ranch Hand
Posts: 415
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

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();
panel1.setLayout(null);
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 ));
panel1.add(button);

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

But the same works fine if i set someother layout than Null Layout
 
Marshal
Posts: 28296
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 415
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving to the Swing forum...
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
panel1 has no size, add this line

panel1.setPreferredSize(new Dimension(200,100));
 
I am going down to the lab. Do NOT let anyone in. Not even this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic