What is the justification for a JavaFX FXML scheme that does not support context menus inside panels?

You can add a context menu to the scroll bar, but not to other types of panels. Why?

+4
source share
2 answers

How FXML Works

FXML works by exploring the Java API, using reflection (or using specialized constructor classes). For more information on how FXML works, see the Introduction to FXML documentation .

Why ContextMenus cannot be defined in panels in JavaFX using FXML markup

contextMenu. A ScrollPane - . , StackPane, . , contextMenu, contextMenu FXML.

.

ContextMenu FXML

( , ) , contextMenu show API, , FXML.

@FXML StackPane stack;

// . . .

public void initialize() {
    final ContextMenu contextMenu = new ContextMenu(new MenuItem("xyzzy"));
    stack.setOnMouseClicked(new EventHandler<MouseEvent>() {
        @Override
        public void handle(MouseEvent mouseEvent) {
            contextMenu.show(
                    stack,
                    mouseEvent.getScreenX(), 
                    mouseEvent.getScreenY()
            );
        }
    });
}

ContextMenu

Node contextMenu, ContextMenus Panes FXML Markup.

, Node contextMenu, Control , ContextMenu . ContextMenu node , JavaFX ( ), . Java, JavaFX, ( , ).

, , SceneBuilder, JavaFX ( , ).

+5

, node . .

. FXML ContextMenu .

BTW, Node.onContextMenuRequested(...) , ?

+1

All Articles