JComboBox控件,不使用setEnabled方法,如何能让其不弹出下拉窗口?谢谢。

解决方案 »

  1.   

        public void firePopupMenuWillBecomeVisible() {
            Object[] listeners = listenerList.getListenerList();
            PopupMenuEvent e=null;
            for (int i = listeners.length-2; i>=0; i-=2) {
                if (listeners[i]==PopupMenuListener.class) {
                    if (e == null)
                        e = new PopupMenuEvent(this);
                    ((PopupMenuListener)listeners[i+1]).popupMenuWillBecomeVisible(e);
                }
            }    
        }重写上面的方法
      

  2.   


    什么马甲,真没看懂,这个问题我也想了解下,我把里面那个for循环屏掉,也没什么变化呀,一样能弹出啊,
    请问高手如何重写??
      

  3.   

    import javax.swing.JComboBox;
    import javax.swing.JFrame;
    import javax.swing.event.PopupMenuListener;public class JComboTest extends JFrame {
    public JComboTest() {
    JComboBox box = new JComboBox(new String[] { "Test" });
    PopupMenuListener[] ls = box.getPopupMenuListeners();
    for (int i = 0; i < ls.length; i++) {
    box.removePopupMenuListener(ls[i]);
    }
    getContentPane().add(box);
    } public static void main(String[] args) {
    JComboTest frame = new JComboTest();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);
    }
    }
    如上面实现,删除JComboBox默认添加的PopupMenuListener即可,当然在删除之前,需要将Listener[]保存,以便以后添加