2016-11-30 10 views
0

リストを使用してjavafxのCellValueFactoryからTableColumnsセルを取り込む方法はありますか?私は私の列に表示する特定の整数のリストを持っていますが、私はこのリストに格納されている整数だけを表示するためにsetCellValueFactoryを適切に使用する方法がわかりません。TableColumn CellValueFactoryをリストに設定する<Integer>

package com.editor.controller; 

import java.util.ArrayList; 
import java.util.List; 

import com.editor.drops.DropManager; 
import com.editor.drops.DropTable; 

import javafx.collections.FXCollections; 
import javafx.collections.ObservableList; 
import javafx.fxml.FXML; 
import javafx.scene.control.TableColumn; 
import javafx.scene.control.TableView; 

public class EditorController { 

@FXML 
private TableView<Integer> idTable; 

@FXML 
private TableColumn ids; //What goes here exactly? <P, S> ? 

private static final ObservableList<Integer> NPCS = FXCollections.observableArrayList(); 

public static final List<DropTable> TABLES = new ArrayList<>(); 

@FXML 
private void initialize() { 
     DropManager.loadDrops(); 
     TABLES.forEach(table -> { 
      table.getIds().forEach(id -> NPCS.add(id)); 
     }); 
} 
} 

答えて

1

あなたはID(整数)のプロパティを持つクラスを作成する必要があり、それはそのようになります。

public class SomeClass { 
    private int id; 

public int getId() { 
    return pid; 
} 

public void setId(int id) { 
    this.id = id; 
} 
} 
public class EditorController { 

@FXML 
private TableView<SomeClass> idTable; 

@FXML 
private TableColumn<SomeClass, Integer> ids; 
private static final ObservableList<Integer> NPCS = FXCollections.observableArrayList(); 

public static final List<DropTable> TABLES = new ArrayList<>(); 

@FXML 
private void initialize() { 
    DropManager.loadDrops(); 
    TABLES.forEach(table -> { 
     table.getIds().forEach(id -> NPCS.add(id)); 
    }); 
ids.setCellValueFactory(new PropertyValueFactory<SomeClass, Integer>("id")); 
} 
} 
関連する問題