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

  • Home
  • SEARCH
  • 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 8059333
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T09:38:33+00:00 2026-06-05T09:38:33+00:00

I have this little part of a program that uses a JComboBox to select

  • 0

I have this little part of a program that uses a JComboBox to select a certain string from it. I found this code on the internet and tried it and it works in the time but when i try to call the string again in a diffrent place after selecting it, it comes back null. Here is the code:

    private class courseAL implements ActionListener{
    public void actionPerformed(ActionEvent e) {
        Start_round sr = new Start_round();
        JComboBox cb = (JComboBox)e.getSource();
        sr.CourseName = (String)cb.getSelectedItem();
        System.out.println(sr.CourseName);
    }
}

It prints out the correct name of the golf course in this situation, but then when i try to call the sr.CourseName again in a diffrent place after selecting it, it prints out null. Help.
Thanks in advance.

  • 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-06-05T09:38:34+00:00Added an answer on June 5, 2026 at 9:38 am

    An ActionEvent is passed upon selection as well as deselection, hence the second one being a deselection of one item before the selection of the new item occurs. By using an ItemListener, you can detect whether the event is a selection or a deselection.

    private class courseAL implements ItemListener {
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                Start_round sr = new Start_round();
                sr.CourseName = (String) e.getItem();
                // alternate:
                // JComboBox cb = (JComboBox) e.getItemSelectable();
                // sr.CourseName = (String) cb.getSelectedItem();
                System.out.println(sr.CourseName);
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this little problem, that I cannot figure out which arguments to pass
I have this little question that's been on my mind for a while now.
I have this little script that shows one wisdom each day. so I have
I have this nice little MSBuild-based daily build setup that I use on my
I'm writing a program in C that uses threads to add up numbers from
This is a bit puzzling here. The following code is part of a little
I've got a little objective-c utility program that renders a convex hull. (This is
I have a c++ program that uses several very large arrays of doubles, and
I have this little rake task: namespace :db do namespace :test do task :reset
I have this little problem. My client wanted two distinct swf on a web

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.