Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ComboBox multiple columns

Status
Not open for further replies.

wangdong

Programmer
Oct 28, 2004
202
CN
I have a combobox with the initial values. The program enables a user to choose one element for configuring. However, the method only accepts a integer value rather than a string. Is there any way to have a two columns combobox and hide the integer field.

Something likes;

3 console mode
6 windows mode
89 listener mode

So, the user only can see all the mode, not the actual number, but the method will accept the number as the peremeter, rather than the mode name.

Chinese Java Faq Forum
 
I would load the ComboBox with your own Objects, not String values.

For example:

Code:
public class Mode
{
  int value;
  String name;
//..getters and setters
  public Mode()
  {
   //things you need for initialization here
  }
  public String toString()
  {
   //return the String you'd like to have displayed
  }
  //other behavior...
}

With your Mode object in hand use the tutorial below to fill the ComboBox up and access the selected Object. You can then pass your Mode into whatever logic you have and query the Mode's getValue() method.

tutorial


Rich

 
Code:
However, the method only accepts a integer value rather than a string

Which method?

Another way is to store a HashTable with the correspondence integer - String.

Cheers,
Dian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top