This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds and have James Denton on-line!
See this thread for details.
Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • 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:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Change the JComboBox list value to another value  RSS feed

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do i change the value from jCombo Box ? without using the if statement

example of jComboBox image


example: if user pick february and wednesday, it will shown as : two three

any idea guys ?

thanks
 
Master Rancher
Posts: 3628
40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use a Map (a HashMap probably).
The Map will have the "February" and "Wednesday" as keys, and "two" and "three" as the associated values.
Then you can get the text from the combo box, pass it to the get method of the map and it will return the value you want.
 
Rancher
Posts: 2940
19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Store a custom object in the model. This object will have two properties:

1. description - used for display in the combo box
2. value - used for processing in the program

Check out Combo Box With Hidden Data for an example of this approach.
 
amir asyraf
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i use netbean add/drop, is the approach still same or any example that can be use in the add/drop netbean  ?

thank mate,


Rob Camick wrote:Store a custom object in the model. This object will have two properties:

1. description - used for display in the combo box
2. value - used for processing in the program

Check out Combo Box With Hidden Data for an example of this approach.

 
Rob Camick
Rancher
Posts: 2940
19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

i use netbean add/drop, 



Why? Don't be restricted by drag/drop features of an IDE. That way you only learn the IDE and not Java/Swing.

Instead write the code yourself and use the IDE to help compile and debug.

I gave you a working example that demonatrates how is it is to create a GUI yourself with the described functionality. So start with that code and add your additional functionality.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!