This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes How to organize panels? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to organize panels?" Watch "How to organize panels?" New topic

How to organize panels?

King-Chieh Wang

Joined: Jan 26, 2004
Posts: 24
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!!
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
KR Campbell
Ranch Hand

Joined: Mar 26, 2004
Posts: 124
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.
Glenn Murray
Ranch Hand

Joined: Dec 07, 2001
Posts: 74
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.

Glenn Murray
Author of Yo Soy Una Vaca De Hoy
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link:
subject: How to organize panels?
It's not a secret anymore!