0

I have a tableview that has columns of types (SimpleStringProperty, SimpleIntegerProperty)

STRING1   STRING2       INTEGER1          INTEGER2
#######   #######       ########          ########

a            b             9                 10
a            c             9                 12
b            d             0                  0

Now, in the 3rd row, the 3rd and 4th column have values as 0. The type of which is SimpleIntegerProperty.

I would like it if the 0s don't show up in the table and the cell appears empty. Can you please advice on how i may do this?

P.S: I am using property listeners for making an editable table. Strings are initialized to null and hence the table is blank but integers are getting initialized to 0.

2 Answers 2

1

I think you have to extend from ListCell and override the updateItem method. In that method you have to check if the SimpleIntegerProperty equals 0 and probably call setText("") then.

Sign up to request clarification or add additional context in comments.

Comments

0

You have to provide a TableCellFactory which returns your customized TableCell-Object. In the TableCell's updateItem()-method you can call setText() as suggested by Lukas Leitinger.

 TableColumn columnInteger2 = new TableColumn("Integer2");
        columnInteger2.setCellValueFactory(
                new PropertyValueFactory<MyVo,String>("fieldInteger2"));

        columnInteger2.setCellFactory(new Callback<TableColumn, TableCell>() {
            @Override
            public TableCell call(TableColumn tableColumn) {
                return new TableCell<String, Integer>(){
                    @Override
                    protected void updateItem(Integer integer, boolean b) {
                        if (integer != null) {
                            super.setText(integer == 0?"":integer.toString());
                        }
                    }
                };
            }
        });

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.