1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
| package test.menubar2;
import javafx.application.Application;
import javafx.application.ConditionalFeature;
import javafx.application.Platform;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.*;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import javafx.stage.Window;
import java.util.stream.IntStream;
public class Main extends Application {
@Override
public void start(Stage stage) throws Exception {
stage.setTitle("Test");
stage.setWidth(800);
stage.setHeight(600);
stage.show();
Platform.runLater(() ->
{
testMenuBar(stage);
if (Platform.isSupported(ConditionalFeature.EXTENDED_WINDOW)) {
testMenuFlow(stage);
}
});
}
private void testMenuBar(final Window owner) {
final var menuBar = new MenuBar();
VBox.setVgrow(menuBar, Priority.NEVER);
IntStream.range(1, 20)
.mapToObj(id -> new Menu("menu_" + id))
.forEach(menuBar.getMenus()::add);
final var scrollPane = new ScrollPane();
VBox.setVgrow(scrollPane, Priority.ALWAYS);
final var root = new VBox();
root.getChildren().setAll(menuBar, scrollPane);
final var scene = new Scene(root);
final var stage = new Stage();
stage.initOwner(owner);
stage.setTitle("Test Menu Bar");
stage.setWidth(800);
stage.setHeight(600);
stage.setX(10);
stage.setY(10);
stage.setScene(scene);
stage.show();
}
private void testMenuFlow(final Window owner) {
final var icon = new Circle();
icon.setRadius(8);
icon.setFill(Color.RED);
final var cornerIcon = new Label();
cornerIcon.setStyle("-fx-border-color: green;");
cornerIcon.setGraphic(icon);
cornerIcon.setAlignment(Pos.TOP_LEFT);
final var menuFlow = new FlowPane();
menuFlow.setStyle("-fx-border-color: cyan;");
menuFlow.setMinHeight(Region.USE_COMPUTED_SIZE);
menuFlow.setMaxHeight(Region.USE_PREF_SIZE);
IntStream.range(1, 20)
.mapToObj(id -> new MenuButton("menu_" + id))
.forEach(menuFlow.getChildren()::add);
final var scrollPane = new ScrollPane();
VBox.setVgrow(scrollPane, Priority.ALWAYS);
final var headerBar = new HeaderBar();
headerBar.setStyle("-fx-border-color: red;");
headerBar.setMinHeight(Region.USE_COMPUTED_SIZE);
headerBar.setMaxHeight(Region.USE_PREF_SIZE);
headerBar.setLeft(cornerIcon);
headerBar.setCenter(menuFlow);
VBox.setVgrow(headerBar, Priority.NEVER);
final var root = new VBox();
root.getChildren().setAll(headerBar, scrollPane);
final var scene = new Scene(root);
final var stage = new Stage();
stage.initOwner(owner);
stage.setTitle("Test Menu Flow");
stage.initStyle(StageStyle.EXTENDED);
stage.setWidth(800);
stage.setHeight(600);
stage.setX(850);
stage.setY(10);
stage.setScene(scene);
stage.show();
}
} |
Partager