reduce the number of the shown characters of all menus. e.g.: |Long fir...|My second...|another...| ...
This is the default behaviour for a MenuBar placed inside a resizable pane.
Here is some sample code using your long menu examples.
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.*;
import javafx.stage.Stage;
public class ElidedMenu extends Application {
@Override public void start(Stage stage) {
MenuBar menuBar = new MenuBar();
Menu menu1 = new Menu("Long first menu");
Menu menu2 = new Menu("My second long entry");
Menu menu3 = new Menu("another long entry");
Menu menu4 = new Menu("Long menu 4");
Menu menu5 = new Menu("My fifth long entry");
Menu menu6 = new Menu("another long long entry");
menuBar.getMenus().addAll(menu1, menu2, menu3, menu4, menu5, menu6);
StackPane stack = new StackPane();
stack.getChildren().add(new Label("Hello World!"));
VBox layout = new VBox();
layout.getChildren().addAll(menuBar, stack);
VBox.setVgrow(stack, Priority.ALWAYS);
stage.setScene(new Scene(layout, 500, 250));
stage.setResizable(false);
stage.show();
}
public static void main(String[] args) { launch(args); }
}
The output of the sample code is:
a solution with a scrollable MenuBar
Wrap the MenuBar in a ScrollPane to make it scrollable.
Here is some sample code using your long menu examples.
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.*;
import javafx.stage.Stage;
public class ScrollingMenu extends Application {
@Override public void start(Stage stage) {
MenuBar menuBar = new MenuBar();
Menu menu1 = new Menu("Long first menu");
Menu menu2 = new Menu("My second long entry");
Menu menu3 = new Menu("another long entry");
Menu menu4 = new Menu("Long menu 4");
Menu menu5 = new Menu("My fifth long entry");
Menu menu6 = new Menu("another long long entry");
menuBar.getMenus().addAll(menu1, menu2, menu3, menu4, menu5, menu6);
ScrollPane scrollingMenu = new ScrollPane();
scrollingMenu.setContent(menuBar);
StackPane stack = new StackPane();
stack.getChildren().add(new Label("Hello World!"));
VBox layout = new VBox();
layout.getChildren().addAll(scrollingMenu, stack);
VBox.setVgrow(stack, Priority.ALWAYS);
stage.setScene(new Scene(layout, 500, 250));
stage.setResizable(false);
stage.show();
scrollingMenu.setPrefSize(stage.getScene().getWidth(), menuBar.getHeight());
}
public static void main(String[] args) { launch(args); }
}
The output of the sample code is: