Results 1 to 6 of 6
Thread: Observable/Observer JComboBox
- 11-27-2010, 03:58 AM #1
Member
- Join Date
- Nov 2010
- Posts
- 11
- Rep Power
- 0
Observable/Observer JComboBox
Hi all, I hope that you can help me with the following issue:
I have an JTabbedPane object which has three tabs. Each tab consists of several components, including an JComboBox object. All tabs are similar.
I need to make these combos are observable/observer objects among them. That is, for instance, when one of them removes an item, everyone should see this change and update itself. Thus, this means that each combo must be observable/observer object.
How can I do for each combo can detects changes and updates its own item list? :confused:
Sorry for my English :(
-
Does each combo box hold the exact same items? If so, the solution is easy -- give all JComboBoxes the same model.
- 11-27-2010, 05:29 AM #3
Um, that'll lock them all to the same selection, which is probably not what's wanted.give all JComboBoxes the same model.
Just guessing here, but I think a custom ComboBoxModel with the data held in a static field might be the best solution. It might even be trivial (or not!) to copy DefaultComboBoxModel and convert some members to static.
db
edit But read the next response tooLast edited by DarrylBurke; 11-27-2010 at 05:43 AM.
- 11-27-2010, 05:43 AM #4
Another approach could be to use a separate ListModel -- possibly a DefaultListModel --and give each combo an extended DefaultComboBoxModel that implements ListDataListener to listen for changes to the shared model and update itself. JComboBox itself implements ListDataListener, but see the doc comments for the three methods it implements.
All changes such as removing an item would be invoked on the shared ListModel.
On second thought, this is probably a better approach (as in more OOPS) than my knee-jerk first suggestion.
db
- 11-27-2010, 05:54 AM #5
Member
- Join Date
- Nov 2010
- Posts
- 11
- Rep Power
- 0
Thanks you for your answer, Fubarable!
I could accomplish what I wanted using your suggest! :)
Thanks you again!
Regards.
- 11-27-2010, 06:03 AM #6
Member
- Join Date
- Nov 2010
- Posts
- 11
- Rep Power
- 0
Similar Threads
-
Pattern Observer
By brontolo in forum Advanced JavaReplies: 6Last Post: 09-02-2010, 02:40 PM -
Have I understood how the observer pattern works?
By kiregad in forum New To JavaReplies: 1Last Post: 05-16-2010, 08:41 AM -
Problem with observer pattern
By livnihai in forum New To JavaReplies: 5Last Post: 10-11-2009, 02:34 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks