如何在TableColumn中添加Long值?

时间:2016-10-26 23:42:42

标签: java javafx scenebuilder

我设法将字符串值打印到我的一个TableColumns中,但是没有显示长值。 我设法找到this回答,但我在.setCellValueFactory上如何使用ObjectProperty?

  

提前谢谢

代码如果需要:

public class MainpageController implements Initializable {

@FXML
private Label label;
@FXML
private TableView<Customer> table1;
@FXML
private TableColumn<Customer, String> NameColumn;
@FXML
private TableColumn<Customer,Long> pnrColumn;

//Table data
final ObservableList<Customer> data = FXCollections.observableArrayList();
//final ObservableList<Customer> data2 = FXCollections.observableArrayList();

@FXML
private void addCustomer(ActionEvent event) throws IOException {
    Parent root = FXMLLoader.load(getClass().getResource("RegCustomer.fxml"));
    Scene s = new Scene(root);
    Stage stg = (Stage) ((Node) event.getSource()).getScene().getWindow();
    stg.setScene(s);
    stg.show();
}

@Override
public void initialize(URL url, ResourceBundle rb) {
    // TODO
    Customer a = new Customer("Lars", 727);
    Customer b = new Customer("Frank", 781);
    BankLogic.kunder.add(a);
    BankLogic.kunder.add(b);
    for (int i = 0; i < BankLogic.kunder.size(); i++) {

        Customer listCust = new Customer(BankLogic.kunder.get(i).getName(), BankLogic.kunder.get(i).getpNr());
        data.add(listCust);

    }
   NameColumn.setCellValueFactory(new PropertyValueFactory<Customer, String>("Name"));
   ObjectProperty<Long> longObjectProperty = new SimpleObjectProperty<Long>();


    table1.setItems(data);
    table1.getColumns().addAll(NameColumn, pnrColumn);



}

}

public class Customer {
String name;
long pNr;

public ArrayList<Object> accounts;

public Customer(String name, long pNr){
    this.name = name;
    this.pNr = pNr;
}

public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}

public long getpNr() {
    return pNr;
}

public void setpNr(long pNr) {
    this.pNr = pNr;
}

0 个答案:

没有答案