JCombobox Listener how to enable it when item is selected?

后端 未结 1 1406
星月不相逢
星月不相逢 2021-01-28 07:16

I have a JComboBox that displays Name From database Patients_Details

public void ComboItem() {

chooser.removeAllItems();
chooser.addItem(\"Please Select...\");         


        
1条回答
  •  孤城傲影
    2021-01-28 08:13

    Simply add an ActionListener to the combo box. When actionPerformed is called, you can look up the selected value and call what ever methods you need to.

    For example:

    chooser.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            Object selectedValue = chooser.getSelectedValue();
            // carry on with what ever you need
        }
    });
    

    Have a look at ...

    • How to write action listeners
    • How to use combo boxes

    For more details

    0 讨论(0)
提交回复
热议问题