我有一个用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)'? –