2016-10-21 5 views
0

tablecolumnの各テーブルセルの値が変数に取得されません。 テーブルビューの各セルの値を取得するにはどうすればよいですか?javafxでtablecolumnの各セルの値を取得して変数に格納する方法

このコードを使用してセル値を取得しようとしましたが、動作していないため、エラーが発生しています。

int mappingid = Integer.parseInt(ocolFileOutputMappingId.getText()); 
    int srno = Integer.parseInt(ocolFileSrno.getText()); 
    String filedname = ocolFieldName.getText(); 

私の完全なコードは次のとおりです。

@FXML 
    private TableColumn<InputMappingFieldModel, Integer> ocolFileSrno;// for srno 

    @FXML 
    private TableColumn<InputMappingFieldModel, Integer> ocolFileOutputMappingId;//thisfor output mapping id 
    @FXML 
    private TableColumn<InputMappingFieldModel, String> ocolFieldName; 


    upaction.setOnAction(evt -> { 
    int index = otableview.getSelectionModel().getSelectedInde); 
    // swap items 
    otableview.getItems().add(index - 1, otableview.getItems().remove(index)); 
    // select item at new position 
    otableview.getSelectionModel().clearAndSelect(index - 1); 

    // code to insert shuffle data in table 
    try { 
    int txtmapoutputid = Integer.parseInt(outputIdText.getText()); 
    String sql = "update OUTPUT_MAPPING set SERIAL_NUMBER=?,FIELD_NAME=?,OUTPUT_MAPPING_ID=? where OUTPUT_ID="+txtmapoutputid; 
    // System.out.println("SQL IS mapping Update "+txtmapinputid); 
    PreparedStatement psmt = conn.prepareStatement(sql); 
    int mappingid = Integer.parseInt(ocolFileOutputMappingId.getText()); 
    int srno = Integer.parseInt(ocolFileSrno.getText()); 
    String filedname = ocolFieldName.getText(); 
    psmt.setInt(1, srno); 
    psmt.setString(2, filedname); 
    psmt.setInt(3, mappingid); 

    psmt.executeUpdate(); 
    } catch (Exception ex) { 
    ex.printStackTrace(); 
    } 

    otableview.getColumns().setAll(ocolFileSrno, ocolFieldName, col_spaceswap, ocolFileOutputMappingId);//remove actionColUpdate from parameter list 
    otableview.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY); 
    otableview.setItems(modelViewField); 
    otableview.refresh(); 
    }); 

は、誰もが親切に私のテーブルビューでテーブルの列のセルの値を取得する方法のためのロジックを提供することができますか?

+1

はあなただけ表示される行の値を好きな理由はありますか? – fabian

答えて

0

短い答えはあなたがセルから値を取得していないということです、あなたは、テーブルの項目リストから値を取得する:

int index = otableview.getSelectionModel().getSelectedIndex(); 
InputMappingFieldModel item = otableview.getItems().get(index); 

// or just 
// InputMappingFieldModel item = otableview.getSelectionModel().getSelectedItem(); 

// this assumes you are using mappingId as the property for ocolFileOutputMappingId: 
int mappingId = item.getMappingId(); 

// and assuming you are using serNo as the property for ocolFieldName 
int serNo = item.getSerNo(); 

// ... 
+0

返信いただきありがとうございます、お試しいただき、あなたにご連絡ください。 –

関連する問題