• Post Reply Bookmark Topic Watch Topic
  • New Topic

Adding 2 panel in a container

 
Meet Gaurav
Ranch Hand
Posts: 492
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

Hoe to add to panel in a container

Container content = getContentPane();
// content.setLayout(new GridBagLayout()); // Used to center the panel
content.add(panel1);
content.add(panel2);
 
Rob Spoor
Sheriff
Posts: 20820
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Without that GridLayout, the Container returned by getContentPane() uses a BorderLayout by default. That means that if you add a component without any constraints, it will add the component to the center. But there can only be one center component, so when you add panel2, panel1 is automatically removed.
 
Meet Gaurav
Ranch Hand
Posts: 492
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob

Thanks for the reply. Any other way to add 2 panels in a Container.
 
harilal ithikkat
Ranch Hand
Posts: 221
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



-----------------------------------------
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!