我想要一個在頂部有一個可調整大小的圖表和在底部有一個固定大小的表格的佈局。我嘗試使用VBox
與Chart
和TableView
,VBox.setVgrow
確保所有調整大小都在圖表上。我事先知道我只會在桌上有三排。VBox中TableView的大小
但是,表格首先顯示比我有更多的行,其次,當調整主窗口大小時也會調整大小。
我在Windows 8.1/64位上使用JDK8更新31。
我設置了我的舞臺這樣
public void start(Stage primaryStage) {
LineChart<Number, Number> chart = new LineChart<>(new NumberAxis(), new NumberAxis());
Node table = makeTable();
VBox.setVgrow(chart, Priority.ALWAYS);
VBox.setVgrow(table, Priority.NEVER);
VBox root = new VBox(chart, table);
Scene scene = new Scene(root, 300, 250);
primaryStage.setScene(scene);
primaryStage.show();
}
,並表被初始化像這樣的(注:所有Color
的東西,只是有一些數據放在表)
private static Node makeTable() {
TableView<Color> table = new TableView<>(FXCollections.observableArrayList(Color.ALICEBLUE, Color.CHARTREUSE, Color.GOLDENROD));
TableColumn<Color, Double> col1 = new TableColumn<>("Red");
TableColumn<Color, Double> col2 = new TableColumn<>("Green");
TableColumn<Color, Double> col3 = new TableColumn<>("Blue");
col1.setCellValueFactory(new PropertyValueFactory<>("red"));
col2.setCellValueFactory(new PropertyValueFactory<>("green"));
col3.setCellValueFactory(new PropertyValueFactory<>("blue"));
table.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
table.getColumns().setAll(Arrays.asList(col1, col2, col3));
return table;
}
有沒有辦法調整表格的內容並修復它?
我已經在桌子上嘗試setMaxHeight
和setPrefHeight
與USE_PREF_SIZE
和USE_COMPUTED_SIZE
沒有效果
您可以嘗試使用minHeight和maxHeight的組合。例如,'table.setMaxHeight(120); table.setMinHeight(120);'。 – ItachiUchiha
這沒有奏效。打印table.getHeight()表明高度*被約束 - 但佈局似乎忽略了這一點。 –