If your tabs are all different then there's no point doing anything other than simple JPanels.
If they all conform to certain style or content standards (eg a background image, or certain controls always in the same place) then its worth creating a subclass of JPanel with all the common elements, and instantiating that for each tab as a starting point.
I can't see any circumstances in which you would benefit from creating different subclasses for each tab.
JamesCherrill
... trying to help
8,526 posts since Apr 2008
Reputation Points: 2,583
Solved Threads: 1,456
Skill Endorsements: 30
Wouldn't the easiest way be to make a super class tab, and define each tab as a subclass? Or am I out of my mind here? :)
You are not out of your mind. That's exactly what I would do (and I suggested something like it in my earlier post), except that there's no value in defining them all as different subclasses. Just create a class with all the common elements, then make the individual tabs instances of that class and add their specific controls as required.
JamesCherrill
... trying to help
8,526 posts since Apr 2008
Reputation Points: 2,583
Solved Threads: 1,456
Skill Endorsements: 30
It's very similar, but he uses subclasses for each tab whereas I would create one "template" class, including all the "duplicate" code, and have one instance per tab. Frankly I don't think that either has a decisive advantage over the other, so go with what you fancy.
For communication I would treat the tabs like any other collection of panels or windows - I'd go MVC (Model-View-Controller) with one or more Model (data) classes and one Controller. The Controller has all the code to manage the flow of logic as you open/close windows and move from tab to tab, and all the tabs share an instance of the Model so they all share the same data.
JamesCherrill
... trying to help
8,526 posts since Apr 2008
Reputation Points: 2,583
Solved Threads: 1,456
Skill Endorsements: 30
Yes.
More specifically:
Controller: yes - high-level controller delegates "tasks" to lower level ones.
View: The whole point is to remove the need for any direct coupling between view classes, so the question of "nesting" doesn't apply here.
Model: The Model is what it is - but some subsets of the application may only use part of it.
So, in summary, "nesting" really only applies to Controllers, where its often a good idea.
JamesCherrill
... trying to help
8,526 posts since Apr 2008
Reputation Points: 2,583
Solved Threads: 1,456
Skill Endorsements: 30
Unless things get particularly complicated I can see no reason why the tabbedpane class can't also be the controller. In smaller apps it's quite common to see the formal MVC structure being simplified into just a couple of classes. It's still a lot better then a free-for-all spaghetti architecture!
JamesCherrill
... trying to help
8,526 posts since Apr 2008
Reputation Points: 2,583
Solved Threads: 1,456
Skill Endorsements: 30
On the contrary, it's absolutely essential. Every view class instance needs a reference to the controller class instance so it can pass requests back up to the controller.
ps: Normally its the controller that creates the new view window/tab, and passes a reference to itself as a param to the constructor. The other common parameter is a ref to the Model instance that this view is expected to work with. So somewhere in the controller you usually see something like:
JComponent aView = new OneOfMyViews(this, theModel);
JamesCherrill
... trying to help
8,526 posts since Apr 2008
Reputation Points: 2,583
Solved Threads: 1,456
Skill Endorsements: 30
Question Answered as of 1 Year Ago by
JamesCherrill
and
hiddepolen