-
Enhancement
-
Resolution: Unresolved
-
P3
-
8u102, 9
Happens if the contextMenu is shown directly in onContextMenuRequested (vs control.setContextMenu - which isn't available for Nodes that are not of type Control anyway).
To reproduce, compile and run the example below
- press F9
- expected: log message printed
- actual: nothing
To make it work, uncomment the access to hidden api. Actually, even this need for additional registration is unexpected - would expect accelerators to "just work" when set on a MenuItem.
In RL it's critical f.i. in contextMenus of TableHeader: see http://stackoverflow.com/q/39721544/203657
import java.util.logging.Logger;
import com.sun.javafx.scene.control.ControlAcceleratorSupport;
//import de.swingempire.fx.util.FXUtils;
import javafx.application.Application;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.ContextMenu;
import javafx.scene.control.MenuItem;
import javafx.scene.input.KeyCombination;
import javafx.scene.layout.BorderPane;
import javafx.scene.shape.Circle;
import javafx.scene.shape.Shape;
import javafx.stage.Stage;
/**
* @author Jeanette Winzenburg, Berlin
*/
public class BugAcceleratorNotNode extends Application {
private Parent getContent() {
ContextMenu circleMenu = new ContextMenu();
MenuItem circleItem = new MenuItem("in Circle");
circleMenu.getItems().add(circleItem);
circleItem.setAccelerator(KeyCombination.valueOf("F9"));
circleItem.setOnAction(e -> LOG.info("action in Circle"));
Shape circle = new Circle(200);
circle.setOnContextMenuRequested(e -> {
LOG.info("requested: " + e);
circleMenu.show(circle, e.getScreenX(), e.getScreenY());
});
// uncomment to make accelerator work
//ControlAcceleratorSupport.addAcceleratorsIntoScene(circleMenu.getItems(), circle);
BorderPane pane = new BorderPane(circle);
return pane;
}
@Override
public void start(Stage primaryStage) throws Exception {
primaryStage.setScene(new Scene(getContent(), 600, 400));
// primaryStage.setTitle(FXUtils.version());
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
@SuppressWarnings("unused")
private static final Logger LOG = Logger
.getLogger(BugAcceleratorNotNode.class.getName());
}
To reproduce, compile and run the example below
- press F9
- expected: log message printed
- actual: nothing
To make it work, uncomment the access to hidden api. Actually, even this need for additional registration is unexpected - would expect accelerators to "just work" when set on a MenuItem.
In RL it's critical f.i. in contextMenus of TableHeader: see http://stackoverflow.com/q/39721544/203657
import java.util.logging.Logger;
import com.sun.javafx.scene.control.ControlAcceleratorSupport;
//import de.swingempire.fx.util.FXUtils;
import javafx.application.Application;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.ContextMenu;
import javafx.scene.control.MenuItem;
import javafx.scene.input.KeyCombination;
import javafx.scene.layout.BorderPane;
import javafx.scene.shape.Circle;
import javafx.scene.shape.Shape;
import javafx.stage.Stage;
/**
* @author Jeanette Winzenburg, Berlin
*/
public class BugAcceleratorNotNode extends Application {
private Parent getContent() {
ContextMenu circleMenu = new ContextMenu();
MenuItem circleItem = new MenuItem("in Circle");
circleMenu.getItems().add(circleItem);
circleItem.setAccelerator(KeyCombination.valueOf("F9"));
circleItem.setOnAction(e -> LOG.info("action in Circle"));
Shape circle = new Circle(200);
circle.setOnContextMenuRequested(e -> {
LOG.info("requested: " + e);
circleMenu.show(circle, e.getScreenX(), e.getScreenY());
});
// uncomment to make accelerator work
//ControlAcceleratorSupport.addAcceleratorsIntoScene(circleMenu.getItems(), circle);
BorderPane pane = new BorderPane(circle);
return pane;
}
@Override
public void start(Stage primaryStage) throws Exception {
primaryStage.setScene(new Scene(getContent(), 600, 400));
// primaryStage.setTitle(FXUtils.version());
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
@SuppressWarnings("unused")
private static final Logger LOG = Logger
.getLogger(BugAcceleratorNotNode.class.getName());
}