please help me in creating a form using Swing.

Discussion in 'Java' started by boris, Aug 10, 2007.

  1. boris

    boris Guest

    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!!:)
     
    boris, Aug 10, 2007
    #1
    1. Advertising

  2. boris wrote:
    >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/a...l#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

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

    Message posted via JavaKB.com
    http://www.javakb.com/Uwe/Forums.aspx/java-general/200708/1
     
    Andrew Thompson, Aug 10, 2007
    #2
    1. Advertising

  3. boris

    boris Guest

    thank you very much.
     
    boris, Aug 10, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Big Daddy

    Java 1.2 Swing vs. Java 1.5 Swing

    Big Daddy, Apr 15, 2005, in forum: Java
    Replies:
    2
    Views:
    503
    Pete Barrett
    Apr 16, 2005
  2. mkrause
    Replies:
    0
    Views:
    674
    mkrause
    May 6, 2005
  3. lizard
    Replies:
    0
    Views:
    1,773
    lizard
    Jan 30, 2006
  4. KK
    Replies:
    2
    Views:
    596
    Big Brian
    Oct 14, 2003
  5. S.T
    Replies:
    2
    Views:
    583
Loading...

Share This Page