• Post Reply Bookmark Topic Watch Topic
  • New Topic

JFrame BorderLayout.CENTER not working on JPanel

 
Sandeep Mukherji
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I made one JFrame. Then created a JPanel and on the JPanel I put labels, textboxes buttons etc. To make the orientation look good I have done jpanel.setLayout(null); and then have done setBounds for the components to be added on the JPanel (i.e. label, textFields and buttons etc...). Now I want that this jpanel should always remain in the center of the JFrame and should not have any influence of the frames resizing. Help me please.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
untested
 
Campbell Ritchie
Marshal
Posts: 52580
119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Most Java programmers prefer to avoid setLayout(null);

If I remember correctly, a JPanel has a FlowLayout as default; if you want to use a BorderLayout the easiest thing is to write

frame.setLayout(new BorderLayout());

before you add anything to it.
 
Campbell Ritchie
Marshal
Posts: 52580
119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Michael Dunn:

Probably a better solution than what I posted, once you have learned to use GridBag.
 
Sandeep Mukherji
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
MANY THANKS TO ALL OF YOU.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!