JComboBox changed event

Posted on 2004-10-29
Last Modified: 2011-09-20
I thought that the ActionPerformed() would fire an event if I changed the selection in a combo box, however fires even when the component is loaded.  What event do I use to fire only when  user makes a selection?

Question by:lomidien
    LVL 37

    Expert Comment

    You should use actionPerformed()
    LVL 37

    Expert Comment

    >> however fires even when the component is loaded
    I use a flag to skip the changes when loading
    LVL 37

    Accepted Solution

    boolean skipChanges = false;

    skipChanges = true;
    // fill up the combobox and make initial selections
    skipChanges = false;

    public void actionPerformed(ActionEvent evt) {
       if (skipChanges) return;

       // do what you want

    Author Comment

    Perfect, thanks a bunch.

    LVL 37

    Expert Comment

    >> however fires even when the component is loaded.
    Rather logical after a second thought, since loading the component = selecting the first item in it
    LVL 37

    Expert Comment

    You're welcome
    Thanks for accepting :°)

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT Security CISA, CISSP & CISM Certification

    Master the advanced techniques required to protect network resources from external threats with the IT Cyber Security bundle. Built around industry best-practice guidelines, the IT Cyber Security bundle consists of three in-depth courses.

    Suggested Solutions

    Title # Comments Views Activity
    Deactivate - DEBUG print on console 2 20
    java JDK Download 7 35
    powerN  challenge 3 20
    nestparen challenge 4 14
    Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
    Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
    Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
    This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

    913 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

    14 Experts available now in Live!

    Get 1:1 Help Now