jmenuitem

How to set a size for JMenuItem?

核能气质少年 提交于 2019-12-06 01:59:42
As you can see, it's ugly to have these kind of JMenuItem s. The width of the menu items is quite small. Here is the code: JMenu menuOne=new JMenu("MenuOne"); JMenu menuTwo=new JMenu("MenuTwo"); JMenu menuThree=new JMenu("MenuThree"); JMenu menuFour=new JMenu("MenuFour"); JMenuBar mbar=new JMenuBar(); //add the menu to menubar mbar.add(menuOne); JMenuItem OneItOne=new JMenuItem("1"); JMenuItem OneItTwo=new JMenuItem("2"); menuOne.add(OneItOne); menuOne.addSeparator(); menuOne.add(OneItTwo); mbar.add(menuTwo); mbar.add(menuThree); mbar.add(menuFour); setJMenuBar(mbar); Simply adding some blanks

How to prevent JMenuItem from closing Menu upon clicking the JMenuItem

折月煮酒 提交于 2019-12-06 00:56:37
How do I prevent a JMenuItem from closing the menu when the JMenuItem is clicked? The JMenuItem is enabled. So this is the scenario, I have 3 JMenuItems : JMenuItem: A, B, C ; C displays an integer X . A and B are used to increment or decrement X by a value of 1. If A or B is clicked, the default nature is that the menu will close upon click. I want to be able to repeatedly click A or B and have the menu remain up, and perform the associated 'action' upon each click. Thanks! First, using a menu to do this may be the wrong approach. JSpinner seems more appropriate. However, to do this with a

Java Swing - Add leniency when selecting items in submenus

强颜欢笑 提交于 2019-12-05 06:29:01
When attempting to click on an item in a submenu, it is natural to quickly draw your mouse across the menu items below it. Both Windows and Mac natively handle this by putting a small delay before the a menu is opened. Swing JMenus do not handle this, and the menu the mouse briefly hovers over would be opened before the mouse reaches the intended menu item. For example, in the image below, if I tried to select Item 3 , but in the process my mouse briefly slid across Menu 2 , the Menu 1 submenu would disappear before I got to it. Does anyone have any tips or suggestions for getting around this?

Adding a vertical separator in PopupMenu, in the task bar

最后都变了- 提交于 2019-12-04 21:42:48
问题 How can I add a vertical separator in the pop up menu of the app in the task bar ? tray = SystemTray.getSystemTray(); openMenuItem = new MenuItem("Open P"); stopKLMenuItem = new MenuItem("Stop"); exitMenuItem = new MenuItem("exit"); menu.add(exitMenuItem); menu.add(stopKLMenuItem); menu.addSeparator(); // adds a horizontal separator menu.add(openMenuItem); trayIcon = new TrayIcon(image,"P",menu); The statement menu.addSeparator() adds a horizontal separator. I also wanted a vertical separator

JMenuItems painting over higher components in JLayeredPane

醉酒当歌 提交于 2019-12-04 11:59:47
I have a set of JMenuItems in a JPanel on one layer of a JLayeredPane, and an emulated cursor painted in a JPanel on a higher layer. When the menu items repaint, they paint over the emulated cursor (without triggering a repaint of the cursor layer). Interestingly, if I substitute JButtons or JLabels for the menu items, the cursor is correctly painted each time the menu items repaint. How can I ensure that repainting the menu items will cause the affected regions of the higher layers to repaint as well, without directly calling repaint() on the layered pane? The situation I've described is

How I can change JMenuItem alignment to right align

独自空忆成欢 提交于 2019-12-04 07:22:17
I have written a program in java with netBeans editor. my form have a jmenuBar with some jmenu in right alignment. for example jmenu1 have some jmenuItem , i want right align all jmenuitem 's text. when i change Horizontal alignment of them to right, text not shown when i run it. menuItem1.setHorizontalAlignment(SwingConstants.RIGHT); How i can do it? http://upcity.ir/images/18431917276667197781.jpg JMenuItem item1 = new JMenuItem("Item 1"); JMenuItem item2 = new JMenuItem("Item ________ 2"); JMenuItem item3 = new JMenuItem("Item 3"); item1.setHorizontalAlignment(SwingConstants.RIGHT); item3

How do you make menu item (JMenuItem) shortcut?

此生再无相见时 提交于 2019-12-03 15:17:34
问题 So i noticed that in awt there is a MenuItem constructor for adding a CTRL + (some key) shortcut, but there is no such constructor for JMenuItem . What is the correct way to do this? I need an equivelent of awt: MenuItem mi = new MenuItem("Copy", new MenuShortcut(KeyEvent.VK_C)); but for Swing. 回答1: Example for CTRL + N . menuItem.setAccelerator(KeyStroke.getKeyStroke('N', Toolkit.getDefaultToolkit ().getMenuShortcutKeyMask())); Toolkit.getDefaultToolkit ().getMenuShortcutKeyMask() returns

How do you make menu item (JMenuItem) shortcut?

流过昼夜 提交于 2019-12-03 05:52:28
So i noticed that in awt there is a MenuItem constructor for adding a CTRL + (some key) shortcut, but there is no such constructor for JMenuItem . What is the correct way to do this? I need an equivelent of awt: MenuItem mi = new MenuItem("Copy", new MenuShortcut(KeyEvent.VK_C)); but for Swing. Dan D. Example for CTRL + N . menuItem.setAccelerator(KeyStroke.getKeyStroke('N', Toolkit.getDefaultToolkit ().getMenuShortcutKeyMask())); Toolkit.getDefaultToolkit ().getMenuShortcutKeyMask() returns control key (ctrl) on Windows and linux, and command key (⌘) on Mac OS. David Kroukamp Simply create a

Change menu bar and menu items font

不打扰是莪最后的温柔 提交于 2019-12-02 15:59:23
问题 I'm trying to make the menu bar items and the items of the items bigger and smaller, I've seached here a bit before (so don't mark this as repeated please) and none of the posts I've found are working. I've tried the following codes without success: Font f = new Font("sans-serif", Font.PLAIN, 12); UIManager.put("menuBar.font", f); And menuBar.setFont(new Font(menuBar.getFont().getFontName(), menuBar.getFont().getStyle(), 12)); And this is my code where I'm trying to edit the font: private

How to make shortcut to invisible menu item in Java

限于喜欢 提交于 2019-12-02 11:58:43
问题 I've recently added a console dialog to my program to make catching bugs easier. This is currently accessible through a JMenuItem and has keyboard shortcut 'Ctrl+L'. Ideally I'd like to keep this option in but make the menu item hidden/invisible, because I only really want people to use it if they are copying the contents to me so I can investigate something. However, when I set the menu item to be invisible the shortcut also stops working. Here's what I've tried: mntmViewLogs.setAccelerator