Reputation: 113
I am very new to JavaFX, I need help in identifying the selected/checked checkbox from the table-view to . See the screenshot for the UI and code i used to the populate data on the table view. I am using scene builder for creating the UI
Code to initialize the table 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);
}
Image of the UI
Here is the data model.
package com.automation.UI;
import javafx.beans.property.SimpleBooleanProperty; import javafx.beans.property.SimpleStringProperty;
public class 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();
}
}
My aim is to get the Description( column next to check) of all the selected checkbox on clicking another button
Upvotes: 1
Views: 1291
Reputation: 3187
There is a couple of ways you can do this the first is to create a list of check boxes and iterate through them and check if(checkBox.isSelected()) otherwise you may have to iterate though all of your nodes to check if it is selected here is an example
List<Object> checkedList = new ArrayList<>();
for (Object node : vbox.getChildren())
if (checkBox instanceof CheckBox)
if (((CheckBox) checkBox).isSelected())
checkedList.add(node);
Then you will have a list of selected checkboxes
Upvotes: 0