This repository was archived by the owner on Jul 5, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Custom menu
Giorgio Garofalo edited this page Feb 5, 2021
·
5 revisions
Chorus' API allows creating custom menus. As for custom previews, a basic knowledge of JavaFX is required.
First of all, we will instantiate a Menu object, which constructor is: Menu(title, isDraggable). The first one specifies the menu title, the second one defines whenever the menu is draggable or not (false if not specified).
const menu = new Menu('My custom menu', true);This will create a new custom menu. Note that it is a JavaFX VBox, so we can define some properties:
menu.setPrefWidth(300);
menu.setSpacing(10); // Space between children
menu.setAlignment(Alignment.CENTER);
menu.setStyle('-fx-padding: 0 0 10 0'); // Adds 10px to the bottom of the menuNow define children:
const textfield = new TextField();
textfield.setPromptText('Name');
const button = new Button('Hello!');
button.setOnAction(e => {
alert('Hello, ' + textfield.getText() + '!');
})
menu.getChildren().addAll(textfield, button);Finally define position, and then show it:
menu.setLayoutX(/* x */);
menu.setLayoutY(/* y */);
menu.show();Output:
Hello, iAmGio!
