如何从javafx上的tableview获取所选复选框的索引

时间:2017-09-15 17:14:30

标签: java javafx javafx-2 javafx-8 scenebuilder

我是JavaFX的新手,我需要帮助从表视图中识别选中/选中的复选框。请参阅屏幕截图,了解用于表视图中填充数据的UI和代码。我正在使用场景构建器来创建UI

初始化表格视图的代码

let sharedDataWithoutBraces = "[\(each.1)]"
    .replacingOccurrences(of: "{", with: "")
    .replacingOccurrences(of: "}", with: "")

用户界面的图片

enter image description here

这是数据模型。

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);
}

import javafx.beans.property.SimpleBooleanProperty; import javafx.beans.property.SimpleStringProperty;

公共类TestSuite {

package com.automation.UI;

}

我的目标是在点击另一个按钮

时获取所有选中复选框的说明(检查旁边的列)

1 个答案:

答案 0 :(得分:0)

有几种方法可以做到这一点,第一种方法是创建一个复选框列表并迭代它们并检查是否(checkBox.isSelected())否则你可能需要迭代所有节点来检查如果在这里选择是一个例子

List<Object> checkedList = new ArrayList<>();
for (Object node : vbox.getChildren())
    if (checkBox instanceof CheckBox)
        if (((CheckBox) checkBox).isSelected())
            checkedList.add(node); 

然后您将拥有所选复选框的列表