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 / General / August 2007

Tip: Looking for answers? Try searching our database.

please help me in creating a form using Swing.

Thread view: 
boris - 10 Aug 2007 13:36 GMT
I am creating a form using SWING.Now in the form I have one JComboBox
of COUNTRY and other of STATE.Now I want it in such a way that when I
select a country from the COUNTRY JComboBox ,the corresponding states
automatically appears in the STATE JComboBox.Please help.
I hope I've put up my query clearly.
Still learning java!!:)
Andrew Thompson - 10 Aug 2007 15:03 GMT
>I am creating a form ..

Form?  Using Netbeans, are you?  Does that translate
to a javax.swing.JFrame?

>..using SWING.

That is 'Swing' (no need to SHOUT).  Please also put
a space, or preferably 2, after each full stop.

>..Now in the form I have one JComboBox
>of COUNTRY and other of STATE.

Normal Java nomenclature would suggest the UPPER_CASE
attribute names mean the member is final.  Other attributes
(and methods) should be camelCase.

>...Now I want it in such a way that when I
>select a country from the COUNTRY JComboBox ,the corresponding states
>automatically appears in the STATE JComboBox.

The COUNTRY combo needs a Listener attached.
Either an ActionListener, or more likely an ItemListener*.
When the listener is activated, (re)populate the STATE
with a new ComboBoxModel**, representing the states.

* <http://java.sun.com/javase/6/docs/api/javax/swing/JComboBox.html#addItemListener
(java.awt.event.ItemListener

)>
** <http://java.sun.com/javase/6/docs/api/javax/swing/JComboBox.html#setModel(javax.
swing.ComboBoxModel

)>

>Still learning java!!:)

A good group for those learning java is comp.lang.java.help.
comp.lang.java.gui specialises in GUI matters.

The JavaDocs (linked above) are invaluable for Java
development.  Download them, bookmark them, or both.
The Java Tutorial has excellent 'trails' on Swing & Events.
<http://java.sun.com/docs/books/tutorial/uiswing/>
<http://java.sun.com/docs/books/tutorial/uiswing/events/index.html>

HTH

Signature

Andrew Thompson
http://www.athompson.info/andrew/

boris - 10 Aug 2007 18:11 GMT
thank you very much.


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.