Trapping a drop-down event on a JComboBox

Since JDK1.4, you can add a PopupMenuListener to your JComboBox and receive the events.

Main.java:

import javax.swing.event.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
import java.awt.*;
 
public class Main extends JFrame { 
   public Main() {
      addWindowListener(new WindowAdapter() {
         public void windowClosing(WindowEvent we) {
            System.exit(1);
         }
      }); 
 
      Vector v = new Vector();
      v.add("first element");
      v.add("second element");
      v.add("third element");
      v.add("fourth element");
      v.add("fifth element");
 
      final JComboBox cb = new JComboBox(v);
      cb.addActionListener(new ActionListener() {
         public void actionPerformed(ActionEvent ae) {
            System.out.println(cb.getSelectedItem());
         }
      });
 
      cb.addPopupMenuListener(new PopupMenuListener() {
         public void popupMenuCanceled(PopupMenuEvent e) {
            System.out.println("PopupMenuCancel Event");
         }
 
         public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
            System.out.println("popupMenuWillBecomeVisible");
         }
 
         public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
            System.out.println("popupMenuWillBecomeInvisible");
         }
      });
      getContentPane().setLayout(new FlowLayout(FlowLayout.LEFT, 10, 10));
      getContentPane().add(new JLabel("Select element:"));
      getContentPane().add(cb);
   } 
 
   public static void main(String []args) {
      Main main = new Main();
      main.setVisible(true);
      main.setSize(300, 150);
   }
}