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

Tony Wolff picture Tony Wolff · Jan 16, 2013 · Viewed 7.2k times · Source

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?

Answer

Reimeus picture Reimeus · Jan 16, 2013

You could do:

comboBox.addFocusListener(new FocusAdapter() {

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