• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Editable drop down combo box

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,
I have an editable combo box that has three values (not counting null.) I need to capture the user's input and do some calculations. Using an array, how do I assign the selection to a variable (double?)
Heather
 
ranger
Posts: 17344
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You probably want to create a FocusListener and use the FocusLost method.

Mark
 
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you look at the Javadocs for JComboBox, you will see that this class as a getSelectedItem() method. Whether you use a listener or not, this is the key method to get what the user typed or selected in the combobox. If you are using straight AWT and not Swing, look at the docs for ComboBox instead. I'm willing to bet it has a similar method, but I'll leave that to you to discover for yourself.

Layne
 
Mark Spritzler
ranger
Posts: 17344
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Layne Lund:
If you look at the Javadocs for JComboBox, you will see that this class as a getSelectedItem() method. Whether you use a listener or not, this is the key method to get what the user typed or selected in the combobox. If you are using straight AWT and not Swing, look at the docs for ComboBox instead. I'm willing to bet it has a similar method, but I'll leave that to you to discover for yourself.

Layne



True, but you can't call getSelectedItem() while you are in the middle of using the JComboBox without a Listener. You can call it anywhere outside the JComboBox though.

Mark
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to Swing/AWT...
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!