2017-09-15 96 views
0

我對JavaFX非常新穎,我需要從表視圖中識別選中/選中複選框的幫助。查看我用於填充表格視圖數據的用戶界面和代碼截圖。我使用場景生成器用於創建UI如何從javafx上的tableview中獲取複選框的選定索引

代碼來初始化表視圖UI

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

圖片的數據模型。

package com.automation.UI; 

import javafx.beans.property.SimpleBooleanProperty; import 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(); 
} 

}

我的目標是獲得描述所有選定的複選框(旁邊的檢查欄)上點擊另一個按鈕

+1

列表什麼是「選擇複選框指數」?你的表有很多複選框,所以可能沒有一個選中的複選框,可能沒有,一個或多個複選框。請更好地解釋一下你需要的數據以及爲什麼你需要它。此外,複選框應該是用戶可編輯的,以便用戶可以點擊它們來改變它們的狀態?用戶可以通過單擊它來選擇表格中的一行(獨立於複選框),您是否在查找有關所選行或複選框的信息?還請包括您的數據模型(TestSuite類)的代碼。 – jewelsea

+0

問題已更新... – Hashili

回答

0

有一對夫婦你可以做到這一點的方法首先是創建一個複選框的列表,並遍歷它們並檢查是否(checkBox.isSelected())否則你可能不得不遍歷所有的節點來檢查它是否被選中在這裏是一個示例

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

然後,你將有選擇的複選框

相關問題