• Post Reply Bookmark Topic Watch Topic
  • New Topic

Which is the best layout?  RSS feed

 
Jennifer Sohl
Ranch Hand
Posts: 455
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi. I have about five JPanels that I want to add one after the other, vertically. Kind of like a FlowLayout, but vertical not horizontal. What is the best layout to use to accomplish this?
Thanks in advance!
 
Travis Kline
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can try:
yourPanel.setLayout(new BoxLayout(yourPanel, BoxLayout.Y_AXIS));
yourPanel.add(panel1);
.
.
yourPanel.add(panel5);
 
Jennifer Sohl
Ranch Hand
Posts: 455
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi. I am trying to use Box Layout, however I have run into a problem. I made a tester class that had 5 different JLabels in it, sizes differing. It worked like I wanted it to. Now I'm trying to use the same class, but with JTextFields, while setting the columns, some long, some short. But when I run it, they are all the same size??? I thought BoxLayout respected preferred size? It does the same with ComboBoxes as well.
Am I missing something?
Any help would be GREATLY appreciated!
 
Michael Crutcher
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you have 5 panels you want to arrange vertically grid layout will be the easiest and provide the best results.
Set the grid 1 column wide and 5 rows tall. Then just add the panels to rows 0 - 4.
Michael Crutcher
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!