• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hierarchical GUI advice

 
T James
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3526
16
Android Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic