Results 1 to 4 of 4
  1. #1
    fahad is offline Member
    Join Date
    Apr 2010
    Posts
    2
    Rep Power
    0

    Default JComboBox and JTextField

    Hello, I am creating a program and I'm using JComboBox and Jtextfield. what i want is when ever the user selects an item from the ComboBox its supposed to show up text for example (A) in the Jtextfield.
    I'm trying to use if statement but i do know how please help
    the combo box model contact :
    5000
    15000
    20000
    25000
    30000
    35000
    40000


    Java Code:
    private void ServiceTypeTextFieldActionPerformed(java.awt.event.ActionEvent evt) {                                                     
    
    
            if (KmsComboBox.equals(5000))
    
            {
                ServiceTypeTextField.setText("A Service");
            }
    
            else
            {
               ServiceTypeTextField.setText(" ");
            }
    
    
        }

  2. #2
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,226
    Rep Power
    6

    Default

    First of all use proper Java Naming conventions which are found in any text book, tutorial or code example you might find. That is variable names start with a lower case letter, NOT an upper case latter.

    You need to get the selected item from the combo box, so the code might be something like:

    Java Code:
    String value = comboBox.getSelectedItem().toString();
    
    if (value.equals("5000")
        // do something
    else
        // do something else

  3. #3
    fahad is offline Member
    Join Date
    Apr 2010
    Posts
    2
    Rep Power
    0

    Default

    Thank you for helping :)
    its work

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

    Default

    Cross posted
    ComboBox and TextField - Java Programming Forums

    fahad didn't bother to inform the other forum that the question has alreday been answered.

    db

Similar Threads

  1. Replies: 2
    Last Post: 12-10-2009, 01:58 PM
  2. JComboBox
    By pinks_70986 in forum New To Java
    Replies: 2
    Last Post: 02-19-2009, 05:26 PM
  3. Replies: 1
    Last Post: 01-30-2009, 06:44 PM
  4. JCombobox
    By daniel50096230 in forum NetBeans
    Replies: 1
    Last Post: 09-21-2008, 12:23 PM
  5. Replies: 2
    Last Post: 07-30-2008, 12:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •