0

I managed to print string values to one of my TableColumns, but long values are just not showing. I managed to find this answer but how exactly do i use ObjectProperty on my .setCellValueFactory?

Thank you in advance

The code if needed:

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;
}
Community
  • 1
  • 1
Softy
  • 65
  • 9
  • Please post the `Customer` class. You don't seem to have a cell value factory set on `pnrColumn`. – James_D Oct 26 '16 at 23:44
  • Customer class edited. I used pnrColumn.setCellValueFactory(new PropertyValueFactory("pnr")); which obv didint work – Softy Oct 26 '16 at 23:52
  • Also related is http://stackoverflow.com/questions/24889638/javafx-properties-in-tableview/24890425#24890425, but I think if you use `PropertyValueFactory` then the types don't actually matter. Change `TableColumn` to `TableColumn` though if you need. – James_D Oct 26 '16 at 23:58
  • James you are a true legend. I changed the input to "Nr" in hope it would get the correct getter but it didint work. I will play around and hopefully fix my problem. Thank you very much! – Softy Oct 27 '16 at 00:03
  • Changed the get method to "getPnr" and it worked. Thank you again james. – Softy Oct 27 '16 at 00:09

0 Answers0