我有一個用fxml和TableView和幾個TableColumns和其他東西寫成的窗口。 我想在這個窗口的控制器中創建一個函數,使用戶能夠通過一組單獨的窗口上的一組複選框來選擇最重要的列。 此窗口將成爲HealthCheckTab的子窗口。它會有一個按鈕,一旦按下就會獲得所有複選框的狀態,並且會調用HealtkcheckTab中的一個函數來更新Tableview,使不需要的列不可見。通過單獨窗口上的CheckBox來隱藏TableView的TableColumns
這與TableView中(提取物)的窗口
</TitledPane>
<TitledPane fx:id="classificationNumbers" animated="false"
text="HealthCheck Classification Numbers">
<content>
<ScrollPane fitToHeight="true" fitToWidth="true"
hbarPolicy="ALWAYS" maxHeight="1.7976931348623157E308"
maxWidth="1.7976931348623157E308" pannable="true">
<content>
<TableView fx:id="HcTable" editable="true"
maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308"
minWidth="-Infinity" tableMenuButtonVisible="true">
<columns>
<TableColumn fx:id="colId" editable="false"
maxWidth="-Infinity" minWidth="40.0" prefWidth="-1.0" text="ID" />
<TableColumn fx:id="colName" editable="false"
maxWidth="1.7976931348623157E308" minWidth="60.0"
prefWidth="-1.0" text="Name" />
<TableColumn fx:id="colVal" maxWidth="1.7976931348623157E308"
minWidth="55.0" prefWidth="-1.0" text="Value" />
<TableColumn fx:id="colDescrCn" editable="false"
maxWidth="1.7976931348623157E308" minWidth="90.0"
prefWidth="-1.0" text="Comment (CN)" />
<TableColumn fx:id="colDatatype" editable="false"
maxWidth="1.7976931348623157E308" minWidth="80.0"
prefWidth="-1.0" text="Datatype" />
<TableColumn fx:id="colTool" maxWidth="1.7976931348623157E308"
minWidth="50.0" prefWidth="-1.0" text="Tool" visible="false" />
<TableColumn fx:id="colPrio" editable="false"
maxWidth="1.7976931348623157E308" minWidth="60.0"
prefWidth="-1.0" text="Priority" />
<TableColumn fx:id="colScope" maxWidth="1.7976931348623157E308"
minWidth="50.0" prefWidth="-1.0" text="Scope" visible="false" />
<TableColumn fx:id="colAvg" editable="false"
maxWidth="1.7976931348623157E308" minWidth="50.0"
prefWidth="-1.0" text="AVG" visible="false" />
<TableColumn fx:id="colMin" maxWidth="1.7976931348623157E308"
minWidth="50.0" prefWidth="-1.0" text="MIN" visible="false" />
<TableColumn fx:id="colRelComp" prefWidth="122.0"
text="Relative Comparable" />
</columns>
</TableView>
</content>
</ScrollPane>
</content>
</TitledPane>
這是控制器(提取物)
@FXML
private TreeView<String> HCTree;
@FXML
private TableView<Map> HcTable;
@FXML
private TableColumn<Map, String> colId;
@FXML
private TableColumn<Map, String> colName;
@FXML
private TableColumn<Map, String> colVal;
@FXML
private TableColumn<Map, String> colDescrCn;
@FXML
private TableColumn<Map, String> colDatatype;
@FXML
private TableColumn<Map, String> colTool;
@FXML
private TableColumn<Map, String> colPrio;
@FXML
private TableColumn<Map, String> colScope;
@FXML
private TableColumn<Map, String> colAvg;
@FXML
private TableColumn<Map, String> colMin;
@FXML
private TableColumn<Map, String> colRelComp;
// -----------------------------------------------------------------------------------------------
// REFRESH TABLE
// -----------------------------------------------------------------------------------------------
public void refreshTable() {
System.out.println("apply");
colScope.setVisible(true);
//colId.setVisible(false);
}
獨立窗口(提取物)
@FXML
private void handleApplyViewOptions() {
try {
FXMLLoader loader = new FXMLLoader(getClass().getResource("HealthCheckTab.fxml"));
Stage stage = new Stage(StageStyle.DECORATED);
stage.setScene(new Scene(loader.load()));
HealthCheckTabController controller = loader.<HealthCheckTabController> getController();
controller.refreshTable();
} catch (IOException e) {
java.lang.System.err.println(e.getStackTrace());
}
Stage stage = (Stage) btnApply.getScene().getWindow();
stage.close();
}
的refreshTable功能根本不隱藏Scope Column。 我不知道爲什麼...
1.「範圍」列顯示索引7,而不是8.(爲什麼不直接調用'colScope.setVisible(...)')2.您期望調用'setVisible(true)'會隱藏什麼? 3.你在哪裏調用'refreshTable()'?我建議你創建一個演示這個問題的[MCVE],然後發佈它,而不是發佈你的項目中不完整的部分(它有很多與問題無關的代碼)。 –
是的,我期待setVisible(true)改變一些事情,我錯過了什麼/做錯了什麼?我遺漏了不必要的部分,並添加了刷新被調用的行...... –
當然,如果你想*隱藏*你會使用'setVisible(false)'? –