aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes GUI layout using HAS-A Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "GUI layout using HAS-A" Watch "GUI layout using HAS-A" New topic
Author

GUI layout using HAS-A

Tony Carolla
Greenhorn

Joined: Dec 05, 2005
Posts: 13
I am learning to build GUIs, specifically for building dynamic queries and displaying the results to the users in real-time.

I designed a prototype, with JLists, JTextFields, and a JTable. To accomodate layout the way I want it, while still using a Layout manager (BoxLayout and FlowLayout), I am nesting components. Basically, I have a JFrame, with a main JPanel in the center, and that JPanel is laid out vertically, and contains two more JPanels, the bottom one contains a JTable, the top contains four panels laid out horizontally, etc. etc.

So it occurred to me that, I am embedding components inside other components, yet I am doing it in one big class. I am not sure where to draw the lines (pardon the pun) with separate classes.

For example, should I make a subclass of JPanel, that contains a JLabel and a JList, then place a ref variable to one of those objects in another subclass of JPanel, which in turn will be represented by another ref variable in another subclass of JPanel?

It just doesn't feel that 'object oriented' if everything for the GUI is embedded in one large class. Any advice would be greatly appreciated.
Brian Cole
Author
Ranch Hand

Joined: Sep 20, 2005
Posts: 862
How many components are we talking about?

If you've got, say, a dozen components I wouldn't
worry about about the nested containers. If you
would be ok putting them all in a single BoxLayout
or FlowLayout, then I don't see how it's any less
"object oriented" to put them in a half-dozen nested
JPanels instead.


bitguru blog
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: GUI layout using HAS-A