Hotkey for JMenuItem of JPopupMenu - java

I have added a JPopupMenu with certain JMenuItems to a JTable in my java application.
I then set accelerators for those JMenuitems.
Now my problem is that when I try to use those hotkeys, they don't work until I open that JPopupMenu.
When that popup menu is open at that time, the hotkey works properly which is really useless. Please help me.

The accelerator bindings only work on components added to the GUI. A popup menu is not added to the GUI until the popup has been invoked.
You can try:
Add you popup menu to the menuBar of your frame. Then the accelerator will be recognized
Manually add the KeyBindings for each accelerator in you popup menu. Read the Swing tutorial on How to Use Key Bindings for more information.

Related

JavaFX Multiple screens with Menubar on top

I am very new to JavaFX. As I am a swing developer, I am facing some problems with JavaFX. In swing I create a main window with JFrame. On the top I add a Menubar. When a menu item is clicked, a JInternalFrame is opened below the Menubar in a JDesktopPane. I've found this way very useful, because I can open any JInternalFrame from menubar as well as from the JInternalFrame itself. The JInternalFrame remains open until user closes them. When user presses escape button he can go back to the previously opened frame.
I've found some libraries that switch scenes. But I cannot find an equivalent way in JavaFX. Can anyone help me to achieve this ?

Java EventHandler on Taskbar Icon

Is it possible to listen for a mouse click on the icon shown in the taskbar (not System Tray)? My problem is that I am using an undecorated window for my GUI, and that causes me to lose the ability to minimize the application by clicking on the taskbar icon. Currently I minimize the application via a button I have added to the scene. Thanks for the help.

Java Quaqua Popup Menu

I have a Java Swing application running on OSX that uses Quaqua. All the TextFields and TextAreas have a popup menu on right click. This must be done by Quaqua as it is not standard in Swing.
My question is:
How do I set my own Actions on the popup menu?
Please Note. This is a question about Quaqua popup menus NOT any Swing popup menu. If you are not familiar about Quaqua then please don't answer.
A pop-up menu is the same as a regular menu. The Swing tutorial about menus covers how to use them, how to insert entries, ... . Reading that tutorial should get you started
The popup menu set by Quaqua can be removed by setting a client property:
myTextField.putClientProperty("Quaqua.TextComponent.showPopup", Boolean.FALSE);
You can then add your own MouseListener to handle creating your own pop up menu.
I haven't figured out, however, to make this change global, and so I have to set the client property on each of my text fields individually, which is a bit of a pain.

Java JMenu CTRL+C shortcut not working

I'm trying to use Ctrl+C, Ctrl+X and Ctrl+V as Swing JMenu shortcut using NetBeans Visual Designer in my app. All of other shortcuts work except these.
What's the problem?
Those Key Bindings are used by default for text components. So if focus is on a text component they will invoke the default Action for the text component.
If you need more help then post your SSCCE that demonstrates the problem.
It is pretty hard to guess what the problem is from your description, but let me guess: do you happen to have JTextArea on the same JFrame? It has some neat property called actionMap (setActionMap(), getActionMap()), which probably has these Accelerators registered.

handling drag and drop and context menu events cross-platform in java

I am building a small GUI application where I use drag and drop internally on custom components. Now I want to have context menus on the components which have drag and drop enabled.
Now my question is, how do I properly distinguish between these two events.
For context menus there is an API function, but for DnD I did not find one.
I used mouse down to trigger DnD, but with that for example on Windows context menus stop working because they are triggered on mouse up.
For DnD use a combination of mouse down and mouse move.
For context menu use the mouse clicked event (so the menu comes up when the mouse button is released not when it's pressed).
The Swing tutorial has sections on "How to Use Menus" and "Drag and Drop".
The section on menus show how to display a popup by checking the "isPopupTrigger" of the MouseEvent. Although since JDK5 this process is easier as the setComponentPopupMenu()method has been added.
The secton on DnD shows how to use the built in DnD support.

Categories

Resources