2012-08-22 51 views
3

当我选择JCombobox时,我希望处理选中的事件并显示下拉菜单,并在下拉菜单消失时处理事件并取消选择JCombobox如何收听JCombobox选择事件

请注意,我并不想要听选项选择更改,但用户选择JCombobox时UI会弹出下拉菜单。

回答

8

你想用addPopupMenuListener它采用如下界面:

public interface PopupMenuListener extends EventListener { 

    /** 
    * This method is called before the popup menu becomes visible 
    */ 
    void popupMenuWillBecomeVisible(PopupMenuEvent e); 

    /** 
    * This method is called before the popup menu becomes invisible 
    * Note that a JPopupMenu can become invisible any time 
    */ 
    void popupMenuWillBecomeInvisible(PopupMenuEvent e); 

    /** 
    * This method is called when the popup menu is canceled 
    */ 
    void popupMenuCanceled(PopupMenuEvent e); 
}