我可以将 ChangeListener 添加到 Scene 并在 scene.widthProperty() 和 scene.heightProperty() 上调用它,但这不适用于通过“最大化”按钮最大化窗口时。
当像 scene.getWindow() 那样访问它时,我找不到窗口的任何 onResize 属性
这是我必须根据调整窗口大小来调整表中列的大小。
当整个窗口最大化时(不符合 scene.widthProperty() 或 scene.heightProperty() 的条件,如何将 resizeColumns 侦听器添加到
ChangeListener<Object> resizeColumns = new ChangeListener<Object>(){
@Override
public void changed(ObservableValue arg0, Object arg1, Object arg2) {
new Thread() {
// runnable for that thread
public void run() {
Platform.runLater(new Runnable(){
public void run() {
// what will be ran in gui thread
Double width =primaryStage.getWidth();
DraftController controller = (DraftController)loader.getController();
TableView<Player> teamTable =controller.getTeamTable();
centerColumns(width, controller, teamTable);
TableView<Player> top10Table = controller.getTop10Table();
AnchorPane anchor = controller.getAnchorPane();
centerColumns(anchor.getWidth()+anchor.getWidth()*.04,controller,top10Table);
}
private void centerColumns(Double width, DraftController controller, TableView<Player> teamTable) {
ObservableList<TableColumn<Player, ?>> columnList = teamTable.getColumns();
for (int i=0 ; i<columnList.size(); i++){
columnList.get(i).setPrefWidth((width-17)/teamTable.getColumns().size());
}
}
});
}
}.start();
}
};
scene.widthProperty().addListener(resizeColumns);
scene.heightProperty().addListener(resizeColumns);
guage: lang-java -->