Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: display item for item selected in combobox

  1. #1
    Junior Member
    Join Date
    May 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default display item for item selected in combobox

    Hi i have table sql with 2 columns i diplay in jCombobox a data from the first column and when i selectItem i want display a message that contains item corresponded if the second columns
    this is the code he always gives me 0
    conn = DriverManager.getConnection("jdbc:mysql://localhost/etat", "root", "123456"); 
                String sql = "SELECT * FROM pop;";         
                PreparedStatement prest = conn.prepareStatement(sql);
                ResultSet res=prest.executeQuery();
        while(res.next()){ 
                 jComboBox3.addItem(res.getString("name")) ; 
                 jComboBox3.setActionCommand(res.getString("etat_syn"));           
        }
     if(jComboBox3.getSelectedItem()!=null){
            System.out.println("Command: " + jComboBox3.getActionCommand());


  2. #2
    Senior Member PhHein's Avatar
    Join Date
    Mar 2013
    Location
    Germany
    Posts
    609
    My Mood
    Sleepy
    Thanks
    10
    Thanked 93 Times in 86 Posts

    Default Re: display item for item selected in combobox

    Have you catually read the APIdoc for JComboBox.setActionCommand? This cannot work.
    How to Use Combo Boxes (The Java™ Tutorials > Creating a GUI With JFC/Swing > Using Swing Components)

Similar Threads

  1. how to display item above....help me to do this...
    By aicue in forum What's Wrong With My Code?
    Replies: 2
    Last Post: January 9th, 2013, 12:40 PM
  2. Replies: 0
    Last Post: December 1st, 2012, 01:06 AM
  3. Replies: 0
    Last Post: February 12th, 2011, 07:44 PM
  4. Problem getting selected item as string from JComboBox
    By lost in forum AWT / Java Swing
    Replies: 1
    Last Post: October 26th, 2010, 03:22 AM
  5. drag item or insert item into new Jlabel in JPanel
    By qaromi in forum AWT / Java Swing
    Replies: 5
    Last Post: July 6th, 2010, 07:37 PM

Tags for this Thread