• Post Reply Bookmark Topic Watch Topic
  • New Topic

Change the JComboBox list value to another value  RSS feed

 
amir asyraf
Greenhorn
Posts: 8
  • 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
 
Dave Tolls
Ranch Foreman
Posts: 2996
37
  • 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.
 
Rob Camick
Ranch Foreman
Posts: 2821
15
  • 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: 8
  • 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
Ranch Foreman
Posts: 2821
15
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!