Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to organize panels?

 
King-Chieh Wang
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everybody,
I am brand new in GUI, so bare with my simple questions here:
I am trying to create a GUI that has 3 textFields, for inputting search strings. Then, a "Submit" button below them , to execute the search. Finally, I would like a JTable , either to the right or bottom of the search field/button to display the results. However, although the textfields and the button works correctly, I cannot make JTable to appear coorectly. I am doing BorderLayout_SOUTH / CENTER / etc for my search fields and button. THen, my JTable either overlapps my button (when I give the BorderLayout_South as coordinate again) or it dont even show up when i put parameter as BorderLayout_East. Whats other way to manage these panels? Also, I wont be able to know how big my JTable will be until I hit the "Submit" button...
THanks for helping out!!
Jack
 
Craig Wood
Ranch Hand
Pie
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
KR Campbell
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or at a more abstract level; if you are using a BorderLayout you cannot add more than one component in each part of the layout. So if you add a button to BorderLayout.CENTER and then add a JTable to the same section one of them is not going to be visible.
As the previous correspondent has so ably demonstrated, a good solution is to nest panels within each other.
Regards,
Kenny
 
Glenn Murray
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, the idea which you seem to be missing is that you can nest
the panels (with their layouts) in one another. Here's a modification
of the example above which shows that more clearly, I think, and
has the further of advantage of not farting around with GridBagLayout
(it's a newbie question for crying out loud). Note that columnPanel
with the GridLayout is nested in northPanel which has the default
FlowLayout---the only purpose being to provide nice padding. You can
experiment by adding columnPanel instead of northPanel in line 25.
Cheers,
Glenn
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic