0

I'm currently trying to allow for a TableView to be a user input source, and in trying to read through tutorials and the like, I'm having a hard time grasping what needs to be done simply to allow population of the table by the user.

Almost every example I see overrides everything, where as the TableCells themselves have a setEdit() method, of which I cannot ascertain how to reference a TableCell itself to call the method.

However, I'm having a hard time working in the reverse direction, and I'm not finding the tutorials very informative of what's going on, only huge amounts code to make something that seems fundamentally simple to get working.

The solution I need only needs to be able to alter string data inside of a cell, does is it really necessary to override every step of the process to just click a cell, have it toggle to editable state, take a string, and then return to a label with text as the string entered?

Also, I'm doing this by FXML, if that makes a difference.

Captain Prinny
  • 459
  • 8
  • 23
  • 1
    Does [`TextFieldTableCell`](http://docs.oracle.com/javase/8/javafx/api/javafx/scene/control/cell/TextFieldTableCell.html) not meet your needs? – James_D Jul 01 '15 at 17:42
  • It would, in theory, buy how do I cause the table to be built out of those rather than labels? – Captain Prinny Jul 01 '15 at 17:51
  • 1
    In Java, `myTableColumn.setCellFactory(TextFieldTableCell.forTableColumn());`. In FXML (I've never tried this approach) `` – James_D Jul 01 '15 at 18:00
  • I knew there had to be a simple solution, why is it that all the tutorials have a minimum of 100 lines of code? I've been looking for this solution for like a week. – Captain Prinny Jul 01 '15 at 18:27
  • works, was a problem with the output from Scene Builder – Captain Prinny Jul 01 '15 at 19:02
  • Does this cell need to be overridden to update on focus lost? – Captain Prinny Jul 01 '15 at 19:07
  • Hmm, good luck with that... http://stackoverflow.com/questions/24694616/how-to-enable-commit-on-focuslost-for-tableview-treetableview/25291137#25291137 – James_D Jul 01 '15 at 19:56

1 Answers1

0

Problem stemmed from Scene Builder defaulting the Table Columns to not being editable, despite the table being editable.

Java

myTableColumn.setCellFactory(TextFieldTableCell.forTableColumn());

FXML

<TableColumn>
    <cellFactory>
        <TextFieldTableCell fx:factory="forTableColumn"/>
    </cellFactory>
</TableColumn>
Captain Prinny
  • 459
  • 8
  • 23
  • You explanation here doesn't really make sense. `TableColumn`s are editable by default, and you don't show any code that changes the `editable` property anyway. What you need is to use `TableCell`s in that column that support editing, which is what your code achieves. – James_D Jul 01 '15 at 20:05
  • They were not editable by default in my code, they were explicitly false in the FXML. – Captain Prinny Jul 01 '15 at 20:14
  • 1
    So you should say that SceneBuilder was explicitly setting the table column editability to false (which is weird, honestly, but then GUI builder tools generally do weird things a lot of the time). – James_D Jul 01 '15 at 20:16