Search code examples
javaswingdrop-down-menujcombobox

how can one make a JComboBox dropdown when it is given focus?


I find that a useful way to draw attention to a jcombobox when one wants the user to select from it is to make it drop down at the point it gains focus usually when the previous item has been completed by the user. How can this been done in Java?


Solution

  • You could do:

    comboBox.addFocusListener(new FocusAdapter() {
    
       @Override
       public void focusGained(FocusEvent e) {
          comboBox.showPopup();
       }
    });