2017-09-15 4 views
0

私はJavaFXの新機能です。テーブルビューから選択/チェックボックスを識別するのに助けが必要です。テーブルビューのデータを入力するために使用したUIとコードのスクリーンショットを参照してください。私はここではUIjavafxのtableviewからチェックボックスの選択インデックスを取得するには

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

画像は、データモデルであるテーブルビューを初期化するためにUI

コードを作成するためのシーンビルダを使用しています。

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

のリストを持っています「を選択し、チェックボックスインデックス」とは何ですか?あなたのテーブルには多くのチェックボックスがあるので、選択されたチェックボックスが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); 

次に、選択したチェックボックス

関連する問題