简体   繁体   English

Java3d applet中的JPopupMenu不接收鼠标或键盘输入

[英]JPopupMenu in Java3d applet does not receive mouse or keyboard input

I have aa Java application that uses Java3D and JPopupMenus filled with JMenuItems. 我有一个Java应用程序,它使用Java3D和JPopupMenus填充JMenuItems。 Everything works fine when it runs as a regular application-- the JPopupMenus and everything else behave as expected. 当它作为常规应用程序运行时,一切正常--JPopupMenus和其他一切都按预期运行。 However, when I make an applet out of the application, the JPopupMenu that pops up entirely over the Canvas3D does not act as expected. 但是,当我从应用程序中创建一个applet时,完全弹出Canvas3D的JPopupMenu没有按预期运行。 The JPopupMenu behaves as follows: JPopupMenu的行为如下:

  1. The menu items do not highlight as the mouse moves over them 当鼠标移过菜单项时,菜单项不会突出显示
  2. The arrow keys cannot be used to move through the menu items 箭头键不能用于在菜单项中移动
  3. Clicking on a top-level JMenuItem completes the action and highlights the item, but it does not dispose of the JPopupMenu as it does in the regular application 单击顶级JMenuItem完成操作并突出显示该项,但它不像在常规应用程序中那样处理JPopupMenu
  4. Clicking on a top-level JMenuItem that contatins a submenu does nothing 单击包含子菜单的顶级JMenuItem不会执行任何操作
  5. Clicking outside of the JPopupMenu does not dispose of the JPopupMenu as it does in the regular application 单击JPopupMenu外部并不像在常规应用程序中那样处理JPopupMenu
  6. With the JPopupMenu displayed, opening a JPopupMenu on top of the swing portion of my program enables regular and expected behavior of the JPopupMenu over the Canvas3D, but point 5 still applies 显示JPopupMenu后,在程序的swing部分顶部打开JPopupMenu可以使Canop3D上的JPopupMenu有规律和预期的行为,但第5点仍然适用

Some more information: 更多信息:

  • The JPopupMenu is displayed with JPopupMenu.show() in relation to the JPanel holding the Canvas3D 使用JPopupMenu.show()显示JPopupMenu与持有Canvas3D的JPanel相关
  • I am calling JPopupMenu.setDefaultLightWeightPopupEnabled(false) before the creation of any JPopupMenus, but this line doesn't seem to make a difference. 我在创建任何JPopupMenus之前调用JPopupMenu.setDefaultLightWeightPopupEnabled(false),但这行似乎没有什么区别。
  • I thought that this might have been a focus issue, but JPopupMenu.requestFocusInWindow() doesn't work 我认为这可能是一个焦点问题,但JPopupMenu.requestFocusInWindow()不起作用

So my question is: what is causing the behavior to be different between the application and the applet, and how can I make the JPopupMenu in the applet function as it does in the application? 所以我的问题是:导致应用程序和applet之间的行为不同的原因是什么,以及如何在applet函数中创建JPopupMenu,就像在应用程序中一样?

您必须将轻量级JPopup更改为重量级,而不必发布其他内容而不发布您的SSCCE

I solved by setting the invoker on the JPopMenu and make it HeavyWeight 我通过在JPopMenu上设置调用者并使其成为HeavyWeight来解决

final JPopupMenu popup = new JPopupMenu();
popup.setLightWeightPopupEnabled(false);
popup.setInvoker(myJFrame);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM