Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/kubernetes/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Event handling netbeans中Jcombobox上的Focuslost事件_Event Handling_Jcombobox_Netbeans 8_Focuslistener - Fatal编程技术网

Event handling netbeans中Jcombobox上的Focuslost事件

Event handling netbeans中Jcombobox上的Focuslost事件,event-handling,jcombobox,netbeans-8,focuslistener,Event Handling,Jcombobox,Netbeans 8,Focuslistener,我试图在组合框上绑定focuslost事件,但没有发生 这是我的密码-: jComboBox1.addFocusListener(new FocusListener(){ public void focusGained(FocusEvent e){ } public void focusLost(FocusEvent e){ JOptionPane.showConfirmDialog(null,"focuslost");

我试图在组合框上绑定focuslost事件,但没有发生

这是我的密码-:

jComboBox1.addFocusListener(new FocusListener(){
        public void focusGained(FocusEvent e){

        }
        public void focusLost(FocusEvent e){
         JOptionPane.showConfirmDialog(null,"focuslost");
          }
      });
我也试过这个-:

JComboBox默认编辑器有一个内部类BasicComboxeditor$BorderlessTextField,它是获取和丢失焦点的组件

只需通过以下方式即可访问:

Component component = comboBox.getEditor().getEditorComponent();  
if (component instanceof JTextField) 
JTextField borderlesstextfield = (JTextField) borderless;
但我在这条线上遇到了错误-

 JTextField borderlesstextfield = (JTextField) borderless;
我对netbeans是新手。请指导我。提前谢谢。

我测试了这个(在JPanel中添加JComboBox)。如果面板中有更多元素,则按tab键或单击其他元素时会触发focuslost

考虑到您没有任何其他元素,或者您希望在单击窗口的某个位置时也触发“焦点丢失”事件:

保持焦点侦听器不变,并在自动生成的
initComponents()之后添加以下内容:


仅供参考:如果不提供赏金,我只能得到一半。其余的都将丢失。当然,我可以接受我的回答可能不够有用。我在任何地方都找不到与我的问题相关的答案。我的问题是,即使按下tab键或单击鼠标,focus lost事件在组合框上也不起作用。注意:面板上还有许多其他元素,但焦点丢失事件对所有元素都有效,但组合框除外。
    jPanel1.setFocusable(true);
    jPanel1.setRequestFocusEnabled(true);
    jPanel1.addMouseListener(new MouseListener() {
        @Override
        public void mouseClicked(MouseEvent e) {}

        @Override
        public void mousePressed(MouseEvent e) {
            jPanel1.requestFocusInWindow();
        }

        @Override
        public void mouseReleased(MouseEvent e) {}

        @Override
        public void mouseEntered(MouseEvent e) {}

        @Override
        public void mouseExited(MouseEvent e) {}
    });