将两个Column值分配给JCombobox

时间:2023-01-27 23:49:08

Could someone tell me how can I assign 2 column values to the JComboBox from mysql database. I want to hide one of the column and show only the other one. however, when retrieving the selected value from the combobox, I want to get the hidden value associated with the selected item."

有人能告诉我如何从mysql数据库中为JComboBox分配2个列值。我想要隐藏其中一个列并仅显示另一个列。但是,当从组合框中检索所选值时,我想获得与所选项目相关联的隐藏值。“

1 个解决方案

#1


2  

Store objects in your combo box:

将对象存储在组合框中:

public class TwoColumns {
    private String hiddenValue;
    private String displayedValue;

    // constructors, getters

    @Override
    public String toString() {
        return displayedValue;
    }
}

This is just an example: you should choose more meaninful names for the class and the fields.

这只是一个例子:您应该为类和字段选择更多有意义的名称。

#1


2  

Store objects in your combo box:

将对象存储在组合框中:

public class TwoColumns {
    private String hiddenValue;
    private String displayedValue;

    // constructors, getters

    @Override
    public String toString() {
        return displayedValue;
    }
}

This is just an example: you should choose more meaninful names for the class and the fields.

这只是一个例子:您应该为类和字段选择更多有意义的名称。