• Post Reply Bookmark Topic Watch Topic
  • New Topic

Need Ideas for Swing Coding Patterns

 
Mohan Panigrahi
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have recently been assigned to devlelop an inhouse swing application. Would appreciate if you could help me with your suggestions for the following problem situation.

The application shall consist of many tabbed panes.
>One such tabbed pane has three/four tabs.
>>Each tab of this is a JPanel.
>>This JPanel has two JPanels and one JListPane
>>> Each of these JPanels and JListPane have their own classes where they have smaller components laid out on them.


Requirement: On click of elements in JListPane, the JPanels should reflect some data.

Question: In what way should I define my event handlers. Is there any pattern I can use. Should I have public get/set methods for each of textboxes which everyone can access?

The problem arises because the Panels are in different classes and cannot access each other components ( like textfields etc. ) to put values on them when different events happen.

Thanks!!
 
clio katz
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
as a start, i would suggest looking at some articles on model-view-controller approaches. a strain of this approach was used in the design of JTable, and you can see the same pattern in other component designs like JList JTree etc.

to answer your question, you almost certainly don't want to expose public getters and setters for your data fields ... this is where a controller can save you some major nightmares.

lastly, you'll want to read some previous posts about the Swing Event Queue. if you're not familiar with the issues there, i'm afraid you soon will be :-T

hth
 
Dave Mace
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Two patterns that I use frequently in my GUIs are: Command Pattern and Mediator Pattern. I think if you do a google on these, you'll get loads of good information.

Essentially, the mediator is what handles communication between classes so that you can keep knowledge from one class out of another class.

David
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!