JComboBox实现类似于HTML的select一般是怎么做的,就是有一个显示值有一个实际值

解决方案 »

  1.   

    就是类似于<select><option value='test'>测试</option><select>
    option 不是有一个value么
      

  2.   

    fontComBox.addItem("A");
    fontComBox.addItem("B");
    fontComBox.addItem("C");
    fontComBox.addItem("D");if(fontComBox.getSelectedItem()=="B")
    System.out.println("B");
      

  3.   

    public class ComboBoxItem {
    private Object value = null;
    private String text = null;

    public ComboBoxItem(Object value, String text)
    {
    this.value = value;
    this.text = text;
    } public Object getValue()
    {
    return value;
    } public String toString()
    {
    return text == null ? "" : text;
    }
    }...
    combobox.add(new ComboBoxItem("test", "测试"));
    ...
    ComboBoxItem item = (ComboBoxItem))combobox.getSelectedItem();
    String value = (String)item.getValue();