English 中文(简体)
禁用 JMEnu 流动
原标题:disable JMenu flowing

在摆动时,我遇到了一个小的应用程序。 我有一个 JMenuBar, 有几个 JMenus, 有些是菜单听众添加的, 他们就像普通按钮( 菜单选择打开一个对话框 ) 。 问题是, 当我点击一个普通菜单, JMenu Frojects 列表展开, 然后在按钮菜单上移动光标时, 菜单听众认为它点击了鼠标和 Lanuches apropiciate 方法 。 如何禁用它? 这里的代码中有一部分是用自定义名称清理的 :

 JMenuBar bar = new JMenuBar();

 addPlayerButton = new JMenu("Button");

 addPlayerButton.addMenuListener(new MenuListener() {

     @Override
     public void menuSelected(MenuEvent e) {
         addPlayerButton.setSelected(false);
         //here comes my method to show custom dialog
     }

     @Override
     public void menuDeselected(MenuEvent e) {
     }

     @Override
     public void menuCanceled(MenuEvent e) {
     }
 });

 bar.add(addPlayerButton);

 JMenu menu = new JMenu("Menu");
 bar.add(menu);
问题回答

我认为你可以使用一个动作倾听器,没有菜单倾听器,没有菜单倾听器。 当鼠标超过菜单时,请选择菜单。Item.Im不确定,但尝试一下。

也许是我太复杂了

想象一下您在其中有一个菜单栏和两个菜单框。 您可以单击其中之一, 并显示其内容 。 现在您将光标移到第二个菜单上, 然后在第二张打开时先关闭。 在此情况下, 我只需要第二张不打开 。





相关问题
How to import an image in menu bar

I ve created a simple menu bar and I don t know how to import an image in the free space. My code is below: import java.awt.event.*; import java.awt.*; import javax.swing.*; import java.io....

How to draw a JMenuBar on top of a graphics

I am writing a basic timer program with Java, and in the program I would like to have a menu bar at the top. The code I have as of now is: public Main() { JMenuBar menubar = new JMenuBar(); ...

How to add a JPopupMenu to a JMenuBar?

I have an application with a popup menu. I d like to use the popup in the usual way (i.e., it should appear when the user right-clicks anywhere in the window), but I d also like to attach it to the ...

add JMenuBar to a JPanel?

I ve got a JMenuBar and a JPanel. I d like to add the JMenuBar to the JPanel. How would I do so?

Java JMenu setAccelerator() problem

When I set setAccelerator() to Control + A or Control + P and I run the program it doesn t detect the keystroke. Here s the code: menuItem = new JMenuItem("About"); menuItem.setActionCommand("...

JMenuBar disappears when I add paint method

Im trying to use the following code to eventually make a game. The code, as shown below, works. import java.awt.event.*; import javax.swing.*; public class GUI extends JFrame implements ...

Java JMenuItem Accelator Snow Leopard

about = new JMenuItem("About"); about.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A((Toolkit.getDefaultToolkit().getMenuShortcutMask())))); JMenu help = new JMenu("Help"); help.add(about); I ...

热门标签