Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java JComboBox Drop Down event

Is it possible to determine when a user clicks on a JComboBox to drop down the list of items in it? I just want to capture this event, not when an item is selected from the list.

Many thanks,

Andez

like image 915
Andez Avatar asked Dec 17 '10 16:12

Andez


People also ask

How do you add a drop down list in Java Swing?

Create a Dropdown Menu Using JComboBox in Javaswing package and is used to show a dropdown list in an interface. Below, we first create the array of options to display in the dropdown list. JComboBox is a component and needs a frame to reside, so we create a JFrame object.

What is the difference between JList and JComboBox?

A JComboBox is a component that displays a drop-down list and gives users options that we can select one and only one item at a time whereas a JList shows multiple items (rows) to the user and also gives an option to let the user select multiple items.

What is JComboBox in Java?

JComboBox is a part of Java Swing package. JComboBox inherits JComponent class . JComboBox shows a popup menu that shows a list and the user can select a option from that specified list . JComboBox can be editable or read- only depending on the choice of the programmer .


2 Answers

You can use JComboxBox#addPopupMenuListener(PopupMenuListener listener)

like image 158
maneesh Avatar answered Oct 28 '22 21:10

maneesh


You can use a PopupMenuListener to determine when the drop down is about to open. Add it using the: addPopupMenuListener-Method.

http://download.oracle.com/javase/6/docs/api/javax/swing/event/PopupMenuListener.html

Use this method

  void popupMenuWillBecomeVisible(PopupMenuEvent e) 
like image 35
Jules Avatar answered Oct 28 '22 23:10

Jules