A simple question about using the JCombobox

Posted on 2004-11-22
Last Modified: 2012-06-27
my code has a JCombobox and is editable. When I type text and press RUTUNE, it will print out what I've typed in. But my problemis: ut print out two times, not just one time. How can I get it just print out one time?

My code looks as follow:

  jComboBoxCommand.addActionListener(new java.awt.event.ActionListener() {
  public void actionPerformed(java.awt.event.ActionEvent e) {    
   System.out.println(jComboBoxCommand.getSelectedItem());                         }
Question by:chenwei
    LVL 37

    Accepted Solution


    jComboBoxCommand.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent e) {    
        // Avoid being triggered twice: for comboBoxChanged & comboBoxEdited:
        if ( !e.getActionCommand().equals("comboBoxChanged") ) return;
        System.out.println(jComboBoxCommand.getSelectedItem());                     }
    LVL 37

    Expert Comment

    Thanks :)

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    Exchange and Third Party application. 8 46
    EvenOdd challenge 10 69
    maxMirror challenge 10 70
    How Complex Is This Java Course ? 9 52
    Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
    Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
    Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
    Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now