【问题标题】:Automatic organization of buttons on a screen自动组织屏幕上的按钮
【发布时间】:2022-09-29 02:10:37
【问题描述】:

我有一个由代码创建的屏幕,在那个屏幕中,我将在 N... 按钮处添加 1,但他们喜欢按钮在屏幕上自我组织,占用所有屏幕空间。但是当添加按钮时,它们被添加到一个队列中。

Stage primaryStage = (Stage) btActivity1.getScene().getWindow();

        Stage stageLayout = new Stage();
        stageLayout.setHeight(primaryStage.getHeight());
        stageLayout.setWidth(primaryStage.getWidth());
        stageLayout.setMaximized(false);

        stageLayout.setTitle(\"Layout: \" + cbListOfRouter.getValue().getSerie());
        stageLayout.initOwner(primaryStage);
        stageLayout.initModality(Modality.APPLICATION_MODAL); 
        
        HBox box = new HBox();
        box.setStyle(\"-fx-background-color: gainsboro; -fx-border-color: gainsboro; -fx-background-radius: 10; -fx-border-radius: 10\");
        box.setPadding(new Insets(10, 20, 10, 20));
        box.setSpacing(5);
        box.setAlignment(Pos.BASELINE_LEFT);
        box.getChildren().addAll(createButtonsLayout());
        box.getChildren().add(new Button());
        
        Vector<Button> listWoButtons = createButtonsLayout();
        int count = 1;
        
        for (Button bt : listWoButtons) {
            box.getChildren().add(bt);
            count++;
        }

        stageLayout.setScene(new Scene(box));
        stageLayout.showAndWait();
  • 使用 FlowPane 而不是 HBox
  • 谢谢詹姆斯,效果很好

标签: javafx


【解决方案1】:

它运作良好

FlowPane box = new FlowPane();
        box.setStyle("-fx-background-color: gainsboro; -fx-border-color: gainsboro; -fx-background-radius: 10; -fx-border-radius: 10");
        box.setPadding(new Insets(10, 20, 10, 20));
        //box.setSpacing(5);
        box.setAlignment(Pos.BASELINE_LEFT);
        box.getChildren().addAll(createButtonsLayout());

enter image description here

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-12-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-15
    相关资源
    最近更新 更多