gpt4 book ai didi

javafx - 如何将 javafx - tableview 大小修复为当前窗口大小

转载 作者:行者123 更新时间:2023-12-01 12:26:38 25 4
gpt4 key购买 nike

我对独立应用程序完全陌生。请任何人帮助我。

我有 6 列的 TableView,它在窗口中显示一半,如下所示。

enter image description here

我想修复它当前的窗口大小,即使窗口被展开,tableview 也应该自动调整大小。有没有办法做到这一点?

这是代码片段

GridPane tableGrid= new GridPane();
tableGrid.setVgap(10);
tableGrid.setHgap(10);
Label schoolnameL= new Label(SCHOOL+school_id);
schoolnameL.setId("schoolLabel");
Button exportDataSheetBtn= new Button("Export In File");
tableView.setMaxWidth(Region.USE_PREF_SIZE);
tableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
tableGrid.getChildren().addAll(schoolnameL,exportDataSheetBtn,tableView);

最佳答案

这可以通过将首选高度和宽度绑定(bind)到初级阶段的高度和宽度来完成。这是 MCVE :

import javafx.application.Application;
import javafx.collections.ObservableList;
import javafx.scene.Scene;
import javafx.scene.control.TableView;
import javafx.stage.Stage;

public class MCVE extends Application {

@Override
public void start(Stage stage) {

TableView<ObservableList<String>> table = new TableView<ObservableList<String>>();

// We bind the prefHeight- and prefWidthProperty to the height and width of the stage.
table.prefHeightProperty().bind(stage.heightProperty());
table.prefWidthProperty().bind(stage.widthProperty());

stage.setScene(new Scene(table, 400, 400));
stage.show();
}

public static void main(String[] args) {
launch();
}

}

关于javafx - 如何将 javafx - tableview 大小修复为当前窗口大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38912047/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com