如何收听JCombobox选择事件

时间:2012-08-22 20:09:00

标签: java swing event-handling jcombobox jpopup

当我选择JCombobox时我想要处理一个事件,当它被选中并显示下拉列表时,以及当下拉消失并取消选择JCombobox时处理事件。 / p>

注意,我不打算听取项目选择更改,但是当用户选择JCombobox并且UI弹出下拉列表时。

1 个答案:

答案 0 :(得分: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);
}