[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

how to determine which option in a combo box is selected

Posted on 2007-04-08
6
Medium Priority
?
227 Views
Last Modified: 2010-03-31
How do I determine which option in a combo box is selected?  MY code is below

I want to be able to say if 1 dollar is selected when you press deposit bill, enter 1 dollar, five dollars enter five.


thanks

billComboBox = new JComboBox();
            billComboBox.setToolTipText("Please select your bill to enter then press deposit bill");
            billComboBox.setModel(new DefaultComboBoxModel(new String[] {"1 Dollar", "5 Dollars"}));

            JButton depositBillButton;
            depositBillButton = new JButton();
            depositBillButton.setText("Deposit Bill");
0
Comment
Question by:urobins
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 24

Accepted Solution

by:
sciuriware earned 2000 total points
ID: 18872851
billComboBox.getSelectedIndex();

gives the index of the selected item [0..N] or -1 if a new item was typed in.

1 Dollar yields 0
5 Dollars yields 1
7 Dollar will produce -1 because it was obviously typed.

billComboBox.getSelectedItem();

gives the selected item at once without indicating new or old.

;JOOP!
0
 
LVL 24

Expert Comment

by:sciuriware
ID: 18872854
And don't forget:

billComboBox.addActionlistener(this); // Makes life easier.

;JOOP!
0
 

Author Comment

by:urobins
ID: 18873000
Thanks I'll try this out and post back!
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:urobins
ID: 18873199
that worked perfect thanks!

although I didn't have to put the actionlistener and when I tried it gave me an error???

Thanks again
0
 
LVL 24

Expert Comment

by:sciuriware
ID: 18873204
Of course an error when your class does not

"implements ActionListener"

forcing a method to be added:

"public void actionPerformed(ActionEvent e)"

But you seem to do without.

Happy Easter.
0
 

Author Comment

by:urobins
ID: 18873208
oh hahahah.... thanks!  I didn't realize that.

thanks have a happy Easter as well!
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses

656 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