0

While accessing the field using getDeclaredField("textField") no longer works from Java12 I am looking for a better way to update the text inside a TreeTableView.

I was thinking of a TextFieldTreeTableCell, would that work? How can be instantiated a TextFieldTreeTableCell from a TreeTableCell? Will be this a better practice to update the text into a TreeTableView?

https://docs.oracle.com/javase/8/javafx/api/javafx/scene/control/cell/TextFieldTreeTableCell.html

Field field = cell.getClass().getDeclaredField("textField");
                field.setAccessible(true);
                Object obj = field.get(cell);

                if (obj instanceof TextField) {
                    TextField textField = (TextField) obj;
                    textField.clear();
                    textField.setText(text);
AndreiD
  • 113
  • 1
  • 11
  • what do you mean? [mcve] please .. – kleopatra Jun 04 '20 at 10:09
  • you don't need reflective access, either lookup or listen to the cell's graphic property – kleopatra Jun 04 '20 at 10:30
  • .. the real question is _why_ do you want that? smells a bit like a x-y-problem :) – kleopatra Jun 04 '20 at 10:41
  • @kleopatra when I have upgraded application JDK from Java8 to Java13 and this no longer work. Might be related to https://stackoverflow.com/questions/56039341/get-declared-fields-of-java-lang-reflect-fields-in-jdk12 – AndreiD Jun 04 '20 at 11:18
  • Why would you have code like this in the first place? If you want the text to change, just change the appropriate value in the model. – James_D Jun 04 '20 at 12:09
  • @James_D, this is exactly what I will try to avoid. I have tried for now a cell.SetGraphic(textField) where I have created a new textField. but doesn't work – AndreiD Jun 04 '20 at 12:16
  • But why are you trying to manipulate the cell at all? Just change the data in the model. – James_D Jun 04 '20 at 12:16
  • .commitEdit(textField.getText())); – AndreiD Jun 04 '20 at 12:18
  • @James_D will it be possible under any circumstances to do it? – AndreiD Jun 04 '20 at 12:21
  • [mcve] please, demonstrating what _exactly_ you want to achieve, how it did work before and doesn't anymore (mind the __M__ and stick to java naming conventions!). – kleopatra Jun 04 '20 at 13:05

0 Answers0