javafx get exactly display text of cell in tableview


Question

this seem a simple question but I can get only the real value of cell, not the display text because I use tableColumn.setCellFactory to change the display text of cell (use a method to convert from real value to my disired text), so the cell will have 2 values: display text and real value. I can re-convert but it's a silly solution :(

cell = t.getColumns().get(col).getCellData(row);
1
5
12/25/2012 12:39:24 PM

You can't access the renderer directly. Among the reasons is that you'd have to access the VirtualFlow that contains the display nodes. However, I give you an answer to the detail information you posted:

In order to make an agnostic export functionality (to CSV, XLS etc.) it would be very convenient to request cell text, rather than data, from a table view. Is that possible?

For any kind of export use a converter.

You never know what target format your users have. Your users could have different number format settings in your JavaFX application than what they have in Excel. Using Excel you need to get your JavaFX model data and set Excel's model data. Don't export using the view data and expect importing in Excel view would work, you'll run into problems.

Same for CSV. If you are e. g. on german localization, a 2 decimals number will look like 123,45 in your table instead of 123.45. So when you export the table's view data, you'll break your CSV format.

You won't get around exporting your model data via a proper converter.

1
2/16/2016 2:24:39 AM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon