无法选择 JCheckBoxMenuItem,上下文中的组件无法识别



我已经开始在机器人框架的 swing 库中工作,在 swing 中测试 java 应用程序。

我必须从jtextarea"showText"上的jpopupmenu"menu"中选择jcheckboxmenuitem "waveMenu"。运行关键字:

Select From Popup Menu      showText        menu|waveMenu

导致一个非常无用的错误。

Fail: Popup menu

如果我尝试右键单击组件 showText,它只是通过而不调出与之关联的菜单。菜单由常规鼠标侦听器附加。

showText.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseReleased(MouseEvent e) {
            if (e.isPopupTrigger()) {
                menu.show(e.getComponent(), e.getX(), e.getY());
            }
        }
    });

从顶部列出上下文中的组件会导致此结果

Level: 0 Component: ca.acme.myApplication
Index: 0 Name: the name I select when I run Select Window
    Level: 1 Component: javax.swing.JRootPane Index: 0 Name: null
       Level: 2 Component: javax.swing.JPanel Index: 0 Name: null.glassPane
       Level: 2 Component: javax.swing.JLayeredPane Index: 0 Name: null.layeredPane
          Level: 3 Component: javax.swing.JPanel Index: 1 Name: null.contentPane
             Level: 4 Component: javax.swing.JPanel Index: 2 Name: null
                Level: 5 Component: javax.swing.JButton Index: 0 Name: fileOpenButton
                Level: 5 Component: javax.swing.JTextField Index: 0 Name: fileText
                Level: 5 Component: javax.swing.JButton Index: 1 Name: fileSendButton
                Level: 5 Component: javax.swing.JLabel Index: 0 Name: null
                Level: 5 Component: javax.swing.JTextField Index: 1 Name: hostText
                Level: 5 Component: javax.swing.JComboBox Index: 0 Name: formatSelect
                   Level: 6 Component: javax.swing.plaf.metal.MetalComboBoxButton Index: 2 Name: null
                   Level: 6 Component: javax.swing.CellRendererPane Index: 0 Name: null
                      Level: 7 Component: javax.swing.plaf.basic.BasicComboBoxRenderer$UIResource Index: 1 Name: null
                Level: 5 Component: javax.swing.JComboBox Index: 1 Name: voiceSelect
                   Level: 6 Component: javax.swing.plaf.metal.MetalComboBoxButton Index: 3 Name: null
                   Level: 6 Component: javax.swing.CellRendererPane Index: 1 Name: null
                      Level: 7 Component: javax.swing.plaf.basic.BasicComboBoxRenderer$UIResource Index: 2 Name: null
                Level: 5 Component: javax.swing.JComboBox Index: 2 Name: delaySelect
                   Level: 6 Component: javax.swing.plaf.metal.MetalComboBoxButton Index: 4 Name: null
                   Level: 6 Component: javax.swing.CellRendererPane Index: 2 Name: null
                      Level: 7 Component: javax.swing.plaf.basic.BasicComboBoxRenderer$UIResource Index: 3 Name: null
                Level: 5 Component: javax.swing.JTextField Index: 2 Name: messageText
                Level: 5 Component: javax.swing.JButton Index: 5 Name: messageSendButton
                Level: 5 Component: javax.swing.JLabel Index: 4 Name: portLabel
                Level: 5 Component: javax.swing.JTextField Index: 3 Name: portText
                Level: 5 Component: javax.swing.JComboBox Index: 3 Name: requestSelect
                   Level: 6 Component: javax.swing.plaf.metal.MetalComboBoxButton Index: 6 Name: null
                   Level: 6 Component: javax.swing.CellRendererPane Index: 3 Name: null
                      Level: 7 Component: javax.swing.plaf.basic.BasicComboBoxRenderer$UIResource Index: 5 Name: null
                Level: 5 Component: javax.swing.JComboBox Index: 4 Name: speedSelect
                   Level: 6 Component: javax.swing.plaf.metal.MetalComboBoxButton Index: 7 Name: null
                   Level: 6 Component: javax.swing.CellRendererPane Index: 4 Name: null
                      Level: 7 Component: javax.swing.plaf.basic.BasicComboBoxRenderer$UIResource Index: 6 Name: null
                Level: 5 Component: javax.swing.JComboBox Index: 5 Name: siteSelect
                   Level: 6 Component: javax.swing.plaf.metal.MetalComboBoxButton Index: 8 Name: null
                   Level: 6 Component: javax.swing.CellRendererPane Index: 5 Name: null
                      Level: 7 Component: javax.swing.plaf.basic.BasicComboBoxRenderer$UIResource Index: 7 Name: null
                Level: 5 Component: javax.swing.JScrollPane Index: 0 Name: null
                   Level: 6 Component: javax.swing.JViewport Index: 0 Name: null
                      Level: 7 Component: javax.swing.JTextArea Index: 4 Name: showText
                   Level: 6 Component: javax.swing.JScrollPane$ScrollBar Index: 0 Name: null
                      Level: 7 Component: javax.swing.plaf.metal.MetalScrollButton Index: 9 Name: null
                      Level: 7 Component: javax.swing.plaf.metal.MetalScrollButton Index: 10 Name: null
                   Level: 6 Component: javax.swing.JScrollPane$ScrollBar Index: 1 Name: null
                      Level: 7 Component: javax.swing.plaf.metal.MetalScrollButton Index: 11 Name: null
                      Level: 7 Component: javax.swing.plaf.metal.MetalScrollButton Index: 12 Name: null

向下级别并尝试与应用程序进行最基本的交互都会导致失败

如果需要,我不介意提供更多细节。多年来,我一直被困在这个问题上。

我发现了这个问题。

if (e.isPopupTrigger()) {
            menu.show(e.getComponent(), e.getX(), e.getY());
        }

Javadoc:

Returns whether or not this mouse event is the popup menu trigger event for the platform. 

我认为窗口弹出菜单触发器与机器人框架摆动库发送的触发器不同。右键单击通过的组件,但什么也没做,因为它实际上通过了;它只是被 if 语句否定了。

相关内容

  • 没有找到相关文章

最新更新