Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6982199
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:15:24+00:00 2026-05-27T18:15:24+00:00

Very new to Java and Swing, and I have been playing with a swing

  • 0

Very new to Java and Swing, and I have been playing with a swing gui application. It generated some code for my combo box:

comboBox.addActionListener(EventHandler.create(ActionListener.class, TestController, "changeSomething"));

and i also have this:

import javax.swing.JComboBox;
import javax.swing.JOptionPane;

public class StudyPlanController {
    private JComboBox factors;

    public void changeSomething() {
        JOptionPane.showMessageDialog(null, "change!");
    }
}

I have 2 questions.

  1. When I change the selected item in the combo box i get the message “change!” only the first time it is changed. Why is this?

  2. When googling for a solution, all the code for setting up the listener was different to the code generated for me. e.g

    box.addItemListener(new ItemListener(){
    public void itemStateChanged(ItemEvent e){
    System.out.println(e.getItem() + ” ” + e.getStateChange() );
    }
    });

Is the way i’m createing the listener correct? why are there two ways to do this?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T18:15:25+00:00Added an answer on May 27, 2026 at 6:15 pm

    For JComboBox is better implements ItemListener, but this Listener is always called twice SELECTED and DESELECTED, you can check that if event is SELECTED/DESELECTED

       myComboBox.addItemListener(new ItemListener() {
    
            @Override
            public void itemStateChanged(ItemEvent e) {
                if (e.getStateChange() == ItemEvent.SELECTED) {
                    //some stuff
                }
            }
        });
    

    You can use ActionListener, but I suggest to use that for changing itself own JComboBox's properties or methods, not to ouside from JComboBox, to ouside somewhere to the GUI

    You can use EventHandler, but better would be start to leaning basic stuff before

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm relatively new to java (specifically swing) and have recently been making some fairly
I'm fairly new to Java and I've been having some difficulties with Swing. I'm
I'm very new to Java but I've been developing a habit to use final
I have developed a Java Swing application, which uses the SwingWorker class to perform
I am developing desktop GUI application using java swing. And I want to show
I am very new to JAVA. I have written simple program (in Linux -VIM
I am trying to link some user docs to my Java Swing application. The
I am very new to Java (only been using it for about a week)
I have a simple Java Swing GUI Form with a browse button. The browse
I am very new to Java, I want to add a PNG image to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.