0

I have created a table in JavaFx. I used reflection to populate the table with numbers 1 to 100. This table contains a zone number and a description. There are 100 zones. I want the table to be editable. I have used the following code to make the cells editable.

zonesTable.setEditable(true);
zone.setEditable(true);
zone.setCellFactory(TextFieldTableCell.<Zones>forTableColumn());

description.setEditable(true);
description.setCellFactory(TextFieldTableCell.<Zones>forTableColumn());

    zone.setCellValueFactory(new PropertyValueFactory<Zones, String>("rZoneNumber"));
    description.setCellValueFactory(new PropertyValueFactory<Zones, String>("rDescription"));

    for(int i = 0; i < 100; i++){
        data.add(new Zones(i + "", "")); 
    }

    zonesTable.setItems(data);

At the moment, this code adds numbers to the zone column and makes the zone and description column editable. However, after I type a value into the column and click the next row, my values that I input into the table disappear. I have no idea why. What do I need to do to cause my typed values to stay visible in the table after I select a different row than the one I am editing? Thanks in advance!

Cannon Moyer
  • 94
  • 1
  • 12

2 Answers2

0

However, after I type a value into the column and click the next row, my values that I input into the table disappear.

It doesn't work because there's a severe, embarrassing bug in JavaFX that Oracle refuses to fix.

The solution for you would be to press enter before you click the next row. But of course you can't request that from your users.

You may find a workaround here.

If you want to upvote the fix and comment on the bug, here's the issue.

Community
  • 1
  • 1
Roland
  • 18,114
  • 12
  • 62
  • 93
0

Not enough code to determine how you work with the table.

  1. You could tableColumn.setOnEditCommit(new CustomEventHandler)
  2. You could tableColumn.setCellFactory(TextFieldTableCell.forTableColumn(new StringConverter() { your logic});

Those still only commit changes in the cell when Enter is pressed. So you will still need your own implementation based on which event you consider to commit edition.

user3224416
  • 522
  • 5
  • 15