Captain Prinny
Captain Prinny

Reputation: 469

JavaFX TableView: Understanding the structure to allow TableCell editing

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.

Upvotes: 0

Views: 348

Answers (1)

Captain Prinny
Captain Prinny

Reputation: 469

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>

Upvotes: 0

Related Questions