MenuItem accelerator: nothing happens or NPE

Werner Lehmann lehmann at media-interactive.de
Mon Jan 7 10:24:04 PST 2013


Hi,

there seem to be some accelerator issues with menuitems. I am asking 
first here before creating Jira tickets - maybe it's a problem in my head...

1. Menuitem accelerator "F1" does not work if used JFXPanel. Pressing F1 
does not trigger the menuitem eventhandler (just like RT-23190?). In 
this case it is supposed to open the online help. Unfortunately we are 
now in a situation where F1 works when any Swing component has focus and 
it silently does not work if the user has clicked on a JFXPanel before.

To work around this we added an event filter for the F1 key_typed event 
and are trying to fabricate key events for the Swing event queue. So far 
without success (on the latter part).

2. In attempt to isolate the problem I created a small test app with a 
menubutton in a stackpane (see below). The menubutton has an item with 
accelerator F1. Pressing F1 throws an NPE. This seems to be the same as 
RT-27192 - with fix version Lombard. Does this mean that menu 
accelerators won't work before 8.0?

Rgds
Werner

> java.lang.NullPointerException
> 	at com.sun.javafx.scene.control.skin.MenuButtonSkinBase$5.run(MenuButtonSkinBase.java:306)
> 	at com.sun.javafx.scene.KeyboardShortcutsHandler.processAccelerators(KeyboardShortcutsHandler.java:296)
> 	at com.sun.javafx.scene.KeyboardShortcutsHandler.dispatchBubblingEvent(KeyboardShortcutsHandler.java:119)
> 	at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:38)
> 	at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:37)
> 	at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92)
> 	at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:35)
> 	at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92)
> 	at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:53)
> 	at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:33)
> 	at javafx.event.Event.fireEvent(Event.java:171)
> 	at javafx.scene.Scene$KeyHandler.process(Scene.java:3509)
> 	at javafx.scene.Scene$KeyHandler.access$2300(Scene.java:3468)
> 	at javafx.scene.Scene.impl_processKeyEvent(Scene.java:1900)
> 	at javafx.scene.Scene$ScenePeerListener.keyEvent(Scene.java:2266)
> 	at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleKeyEvent(GlassViewEventHandler.java:127)
> 	at com.sun.glass.ui.View.handleKeyEvent(View.java:518)
> 	at com.sun.glass.ui.View.notifyKey(View.java:951)
> 	at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
> 	at com.sun.glass.ui.win.WinApplication.access$100(WinApplication.java:29)
> 	at com.sun.glass.ui.win.WinApplication$3$1.run(WinApplication.java:73)
> 	at java.lang.Thread.run(Unknown Source)


> public class ShortcutTest extends Application
> {
>   public static void main(String[] args)
>   {
>     Application.launch(args);
>   }
>
>   @Override
>   public void start(Stage stage) throws Exception
>   {
>     MenuItem menuItem = new MenuItem("Help");
>     menuItem.setAccelerator(new KeyCodeCombination(KeyCode.F1));
>     menuItem.setOnAction(new EventHandler<ActionEvent>() {
>       @Override public void handle(ActionEvent paramT) { System.err.println("menuitem action"); }
>     });
>
>     MenuButton button = new MenuButton("click me or press F1");
>     button.getItems().add(menuItem);
>
>     StackPane stackPane = new StackPane();
>     stackPane.setPrefSize(300, 200);
>     stackPane.getChildren().add(button);
>
>     stage.setScene(new Scene(stackPane));
>     stage.show();
>   }
> }




More information about the openjfx-dev mailing list