aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Hierarchical GUI advice Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Hierarchical GUI advice" Watch "Hierarchical GUI advice" New topic
Author

Hierarchical GUI advice

T James
Greenhorn

Joined: Aug 09, 2012
Posts: 2
I currently have a simple GUI with a somewhat hierarchical structure:

main JFrame with contentPane JPanel
-inside the contentPane is a JTabbedPane
--the JTabbedPane has 3 tabs, each with a JPanel as well
---the first JPanel is composed of 5 - 6 more Panels with different components within them
----Panel of buttons only, Panel of static text, Panel of Input Fields, Panel of Comboboxes, etc)

Questions:
1. Am I right in separating components into their respective "Panels of something" or should I put all components in the next higher Panel (e.g. first Panel of the JTabbedPane) ?

2. In my implementation of a Model-View-Controller, should I refer to the methods in the components of the View or the View itself?

example:
My View(JFrame) has a contentPane(JPanel) with a tabbedPane(JTabbedPane).
The tabbedPane has a samplePane(JPanel) as its first tab.
The samplePane has a buttonPanel(JPanel) with 6 buttons.
One of the buttons is a saveButton with a method .saveMode()

Solution 1:
In my Controller, should I invoke .saveMode() this way?Solution 2:
Would I rather transfer the long part to the View with a method on the View itself? Solution 3:
I would cascade the method in the entire heirarchy so each parent container has a method to pass the call?

I am kinda confused in how to make readable/maintainable code when creating more complex/hierarchical GUI.
Thanks for any and all advice on how to improve my GUI skills.
K. Tsang
Bartender

Joined: Sep 13, 2007
Posts: 2503
    
    8

T James wrote:I currently have a simple GUI with a somewhat hierarchical structure:

main JFrame with contentPane JPanel
-inside the contentPane is a JTabbedPane
--the JTabbedPane has 3 tabs, each with a JPanel as well
---the first JPanel is composed of 5 - 6 more Panels with different components within them
----Panel of buttons only, Panel of static text, Panel of Input Fields, Panel of Comboboxes, etc)

Questions:
1. Am I right in separating components into their respective "Panels of something" or should I put all components in the next higher Panel (e.g. first Panel of the JTabbedPane) ?

2. In my implementation of a Model-View-Controller, should I refer to the methods in the components of the View or the View itself?

example:
My View(JFrame) has a contentPane(JPanel) with a tabbedPane(JTabbedPane).
The tabbedPane has a samplePane(JPanel) as its first tab.
The samplePane has a buttonPanel(JPanel) with 6 buttons.
One of the buttons is a saveButton with a method .saveMode()



Hi your components looks alright to me. You are really working out the layout of your JPanel in one of the tabs of the JTabbedPanel.

Remember each JPanel can have its own layout manager with the default flow layout.

For code organization, I suggest separate the actions/events into their own classes for better control. As for the view, depending on how separate you want, you can have a class for each component and have a parent class/view adding each components to the JFrame/JPanel. Of course too much separation isn't good. So I suggest you work on each panel or sub-panel as a time.

Also naming convention and/or packaging for your classes will also help especially if you decide to separate components into classes.

Hope this helps.

K. Tsang JavaRanch SCJP5 SCJD/OCM-JD OCPJP7 OCPWCD5 OCPBCD5
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Hierarchical GUI advice