jmenu

Focus on first jmenubar item on “alt” key press

不羁的心 提交于 2019-12-22 12:07:09
问题 Is there any way to auto-select a jmenu within my jmenubar when the user's pressing the "ALT" key ? (Like windows softwares) The problem is that the default behavior of my jframe, when the "ALT" key is pressed, is to show up a menu containing the following actions : restore, move, size, reduce, ... What I want my java application to do, is to select my jmenu first item when "alt" is pressed. (Like it would do with a mnemonic : "alt + f") 回答1: Add the action to the ActionMap and InputMap of

Can JTable cell edit consume key strokes?

こ雲淡風輕ζ 提交于 2019-12-22 00:55:08
问题 In my program, there is a JMenu with many accelerators, and a JTable that is editable. Problem is, when editing the JTable, the accelerator keys still get triggered. E.g., if I enter the letter 'n' into the jtable cell, the 'next' menu option fires as well. How would one go about making the jtable cell editor consume the keystrokes exclusively? import javax.swing.JFrame; import javax.swing.JMenuBar; import javax.swing.JMenu; import javax.swing.JMenuItem; import javax.swing.JTable; import

JMenu consumes focuslost event in Windows7 LAF Java7

北城余情 提交于 2019-12-19 10:43:24
问题 If a popup menu is still open when another component is clicked, then the component does not get the event, because it's probably consumed by the popup. This happens for all JPopupmenus in general. This happens only in Java 7 with windows LAF (Windows7). Is there a workaround? Is it a known bug? import javax.swing.*; import java.awt.event.*; public class Test { public static void main(String[] s) throws Exception { String lookAnfFeelClassName = UIManager.getSystemLookAndFeelClassName();

JMenu consumes focuslost event in Windows7 LAF Java7

梦想与她 提交于 2019-12-19 10:42:26
问题 If a popup menu is still open when another component is clicked, then the component does not get the event, because it's probably consumed by the popup. This happens for all JPopupmenus in general. This happens only in Java 7 with windows LAF (Windows7). Is there a workaround? Is it a known bug? import javax.swing.*; import java.awt.event.*; public class Test { public static void main(String[] s) throws Exception { String lookAnfFeelClassName = UIManager.getSystemLookAndFeelClassName();

How to make a JMenu have Button behaviour in a JMenuBar

不打扰是莪最后的温柔 提交于 2019-12-19 07:28:22
问题 I was trying to make a JMenu behave like a JButton but I'm having some problems and hopefully someone here can help! I've added a MenuListener to the JMenu item with this but I cant get the popup menu/focus to leave to enable me to properly click the JMenu repeated times to trigger this function and i was hoping someone could tell me what i'm doing wrong. Thanks. public void menuSelected(MenuEvent e) { ... // do stuff here code JMenu source = (JMenu)e.getSource(); source.setSelected(false);

How to set an accelerator for a JMenu sub menu?

南笙酒味 提交于 2019-12-12 12:20:47
问题 I have a user request to add an accelerator to a sub menu (JMenu) which would allow the user to press the short cut and have the corresponding sub menu "fold out", showing its contained menu items. I don't recall every having seen something like this (either in Java or any other language). Our application is written in Java using Swing. We have a number of JMenuItems with accelerators that work well, but when I attempted to add an accelerator to JMenu I get the following exception: java.lang

Java/Swing/Mac OSX: Converting JMenu to JPopupMenu using ScreenMenuBar

旧巷老猫 提交于 2019-12-12 03:32:11
问题 I have an application that has a main GUI with a menubar, and another fullscreen frame, which makes some parts of the main GUI appear in fullscreen exclusive mode. When I am in fullscreen mode, I would like to bind a drop-down menu from the menu bar as jpopupmenu. Swing provides the function getPopupMenu() in JMenu. This function seems to work fine at first glance. I can hover over the menuitems and move to and view the submenus. Hovering over the submenus does emphasize the submenus,

Is it possible to remove a JMenuItem from a JMenu given only the String associated with the JMenuItem

百般思念 提交于 2019-12-12 03:05:16
问题 I have a JMenu populated with JMenuItems from a database that have listeners, one of them being to delete the entry from the database if selected. When this happens that JMenuItem should disappear from the menus. Here's a short bit as an example for (final Racer r : Racer.getAllRacers()) { JMenuItem j = new JMenuItem(r.getName()); racerDelete.add(j); j.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { int reply = JOptionPane.showConfirmDialog(null, "Are you

Java setPressedIcon not working

巧了我就是萌 提交于 2019-12-11 23:19:46
问题 I have menu in my application, and I want to set menu item normal state icon, and pressed state icon. Normal state icon is added, but when I press menu item, normal state icon is not changed by pressed state icon. What is problem here: JMenu m=new JMenu(text); m.setBackground(getTheme().colors.menuColor()); m.setOpaque(false); m.setIcon(core.getIcon(text, "normal")); m.setPressedIcon(core.getIcon("webmaps", "pressed")); 回答1: This issue has been seen before. The inherited setPressedIcon does

Adding Menubar to JFrame

泪湿孤枕 提交于 2019-12-11 11:14:28
问题 I have the following source code and i just dont get why my menubar/menu wont show on the JFrame, im somewhat new to programming public class drawingApp { public static void main(String[] args) { JFrame frame = new JFrame("DrawingApp"); frame.setSize(600,800); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); frame.setLocationRelativeTo(null); JMenuBar mb = new JMenuBar(); JMenu menu1 = new JMenu("Colour"); mb.add(menu1); JMenu menu2 = new JMenu("Size"); mb.add