JavaFX 19: Not able to get int columns in a tableview editable

42 Views Asked by At

Java is new to me and I've been trying to make an int column editable in a TableView for 1.5 days. I know many examples exist here, but they all don't work for me (for whatever reason). One example that I have found very often would be:

colID.setCellFactory(TextFieldTableCell.forTableColumn(new IntegerStringConverter()));

but this leads me to a message about incompatible types. I would need once only a short example of what works. Also, I would be interested to know why the many examples found here do not work for me. I am using JavaFX19, can this be the reason?

It would be great if someone could help me with this. Thank you...

That is my Customer class and I want to edit the ID column and the method in my CotrollerClass causing the problems on setCellFactory...


public class Customer {

/**
* Standardkonstruktor
*/
public Customer(){}

/**
* Konstruktor zur Erzeugung gefüllter Customer-Objekte
* @param id ID des Customers
* @param vorName Vorname des Customers
* @param nachName Nachname des Customers
*/
public Customer(int id, String vorName, String nachName){
    intID = id;
    strVorName = vorName;
    strNachName = nachName;
}

public int getID() {
    return intID;
}

public void setID(int id) {
    this.intID = id;
}

public String getVorName() {
    return strVorName;
}

public void setVorName(String vorName) {
    this.strVorName = vorName;
}

public String getNachName() {
    return strNachName;
}

public void setNachName(String nachName) {
    this.strNachName = nachName;
}    

// <editor-fold defaultstate="collapsed" desc=" Klassenvariablen ">

private int intID;
private String strVorName;
private String  strNachName;    

// </editor-fold>

}


private void rebindData(){
    tblCustomers.setItems(customers);

    colID.setCellValueFactory(new PropertyValueFactory<>("ID"));
    colGivenName.setCellValueFactory(new PropertyValueFactory<>("VorName"));
    colName.setCellValueFactory(new PropertyValueFactory<>("NachName"));
            
    /************************************************************/
    //colID.setCellFactory(TextFieldTableCell.forTableColumn());
    /************************************************************/
    
    
    colID.setCellFactory(TextFieldTableCell.forTableColumn(new IntegerStringConverter()));

    
    //void setCellFactory(Callback<TableColumn<Customer, String>, TableCell<Customer, String>> value) - parameters
    //public static <S,T> Callback<TableColumn<S,T>,TableCell<S,T>> forTableColumn(StringConverter<T> converter)
    
    colGivenName.setCellFactory(TextFieldTableCell.forTableColumn());
    colGivenName.setOnEditCommit(event-> {
        event.getRowValue().setVorName(event.getNewValue());
    });
    
    colName.setCellFactory(TextFieldTableCell.forTableColumn());
    colName.setOnEditCommit(event-> {
        event.getRowValue().setNachName(event.getNewValue());
    });
    
    tblCustomers.refresh();
}    

0

There are 0 best solutions below