How to make a table column with Integer datatype editable without changing it to String

后端 未结 2 1814
傲寒
傲寒 2020-12-18 04:22

I have a table column with datatype Integer. i want to make this column editable without changing the datatype to String anywhere. I used textfieldtablecell but it commits v

2条回答
  •  误落风尘
    2020-12-18 04:52

    You can create table cell with StringConverter, that will convert your object to cell presentation. You can realize own StringConverter for your class

    cell.setCellFactory(TextFieldTableCell.forTableColumn(new StringConverter() {
    
            @Override
            public String toString(AnyClass object) {
                return null;
            }
    
            @Override
            public AnyClass fromString(String string) {
                return null;
            }
        }));
    

    Also JavaFX contains some default converters. E.g. IntegerStringConverter for your case,

    TextFieldTableCell.forTableColumn(new IntegerStringConverter())
    

提交回复
热议问题