我对 JavaFX 非常陌生,我需要帮助来识别从 TableView 到 .请参阅我用于在 TableView 上填充数据的 UI 和代码的屏幕截图。我正在使用场景生成器来创建 UI
初始化表格 View 的代码
public void initialize(URL location, ResourceBundle resources) {
ddUrls.setItems(urls);
ddbrowserNames.setItems(browsers);
ddFrames.setItems(frames);
//testClassCl.setCellValueFactory(new PropertyValueFactory<TestSuite,String>("testClass"));
testMethodCl.setCellValueFactory(new PropertyValueFactory<TestSuite,String>("testMethod"));
testDescCl.setCellValueFactory(new PropertyValueFactory<TestSuite,String>("testDesc"));
//runModeCl.setCellValueFactory(new PropertyValueFactory<TestSuite,Boolean>("runMode"));
runModeCl.setCellFactory(column -> new CheckBoxTableCell());
table.setItems(list);
table.setEditable(true);
}
用户界面图像
这是数据模型。
package com.automation.UI;
导入javafx.beans.property.SimpleBooleanProperty; 导入 javafx.beans.property.SimpleStringProperty;
公共(public)类 TestSuite {
private SimpleStringProperty testClass;
private SimpleStringProperty testMethod;
private SimpleStringProperty testDesc;
private SimpleBooleanProperty runMode;
public TestSuite(String testClass, String testMethod, String testDesc, boolean runMode) {
this.testClass = new SimpleStringProperty(testClass);
this.testMethod = new SimpleStringProperty(testMethod);
this.testDesc = new SimpleStringProperty(testDesc);
this.runMode = new SimpleBooleanProperty(runMode);
}
public String getTestClass() {
return testClass.get();
}
public String getTestMethod() {
return testMethod.get();
}
public String getTestDesc() {
return testDesc.get();
}
public boolean getRunMode() {
return runMode.get();
}
}
我的目标是在单击另一个按钮时获取所有选定复选框的说明(检查旁边的列)
最佳答案
有几种方法可以做到这一点,第一种是创建复选框列表并迭代它们并检查 if(checkBox.isSelected()) 否则您可能必须迭代所有节点以检查它是否被选中,这是一个示例
List<Object> checkedList = new ArrayList<>();
for (Object node : vbox.getChildren())
if (checkBox instanceof CheckBox)
if (((CheckBox) checkBox).isSelected())
checkedList.add(node);
然后您将看到选定复选框的列表
关于java - 如何从javafx中的tableview获取复选框的选定索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46244650/