Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / January 2008

Tip: Looking for answers? Try searching our database.

Two JComboBoxes One change to other

Thread view: 
RC - 28 Jan 2008 17:59 GMT
I have two JComboBoxes

JComboBox combo1 = new JComboBox();
JComboBox combo2 = new JComboBox();

Both I implemented the ItemListener
Now I want if combo1 itemStateChanged(ItemEvent evet)
then combo2 also itemStateChanged.

Vice versa, if combo2 itemStateChanged, then combo1 also
itemStateChanged.

Any idea how to do that?

Thank Q in advance!
Andrew Thompson - 29 Jan 2008 00:37 GMT
...
> Any idea how to do that?

Did you try reading the documentation?
<http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/
JComboBox.html#setSelectedIndex(int)>
<http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/
JComboBox.html#setSelectedItem(java.lang.Object)>

The 1.4 JDcos were the first Google found.
I expect the 1.6 docs will say the same.

(F/U set to c.l.j.h. only)

--
Andrew T.
PhySci.org
brahma.mca07@gmail.com - 30 Jan 2008 05:35 GMT
> I have two JComboBoxes
>
[quoted text clipped - 11 lines]
>
> Thank Q in advance!

hi
your question is quite intresting.............you want to use to
associated events & both are inter related ........................so
you must serialize them.........i thing its better to use boolean
variable to serialize events ......................
                                              thanks
Roedy Green - 30 Jan 2008 09:46 GMT
>Vice versa, if combo2 itemStateChanged, then combo1 also
>itemStateChanged.
>
>Any idea how to do that?

Use a listener that sets the state of the other.  the problem is you
get fibrillation, where each change triggers another, ad-infinitum.

So you must set a boolean somewhere to say, "ignore trigger"

When you get a trigger you check the boolean.  If it says ignore, you
set it false and do nothing. If it is false you set it true and
trigger the other widget.
Signature

Roedy Green, Canadian Mind Products
The Java Glossary, http://mindprod.com

Daniele Futtorovic - 30 Jan 2008 10:16 GMT
>> Vice versa, if combo2 itemStateChanged, then combo1 also
>> itemStateChanged.
[quoted text clipped - 9 lines]
>  set it false and do nothing. If it is false you set it true and
> trigger the other widget.

Depends on whether the relationship between his two models is bijective,
though, that is whether any item of any of the two models is mapped to
exactly one of the other model. If it is, it should work alright, since
calling setSelectedItem with the currently selected item (may be null)
doesn't fire any ItemEvent (though it does fire an ActionEvent).

Follow-up to c.l.j.g


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.