[英]How to get the selected index of checkbox from tableview on javafx
我是JavaFX的新手,我需要幫助來識別從表視圖到的選中/選中的復選框。 請參閱屏幕快照,以獲取用於在表視圖上填充數據的UI和代碼。 我正在使用場景構建器來創建UI
初始化表格視圖的代碼
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;
公共類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();
}
}
我的目的是在單擊另一個按鈕時獲得所有選中復選框的Description(檢查旁邊的列)
有兩種方法可以執行此操作,第一種方法是創建復選框列表並對其進行遍歷並檢查if(checkBox.isSelected()),否則可能需要遍歷所有節點以檢查是否為這里選擇的是一個例子
List<Object> checkedList = new ArrayList<>();
for (Object node : vbox.getChildren())
if (checkBox instanceof CheckBox)
if (((CheckBox) checkBox).isSelected())
checkedList.add(node);
然后,您將看到一個選定復選框的列表
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.