After many hours of reading and trying I have been struggling with populating editable TextField containers within a TableView.
I already managed to display data from an ObservableList of a custom object to my TableView instance.
I already tried this command:
spalteTag.setCellFactory(TextFieldTableCell.forTableColumn(spalteTag));
But this gives an error whereas this type of code
spalteIstErledigt.setCellFactory(CheckBoxTableCell.forTableColumn(spalteIstErledigt));
works properly.
package sample;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.scene.control.*;
import javafx.scene.control.cell.CheckBoxTableCell;
import javafx.scene.control.cell.TextFieldTableCell;
import javafx.util.converter.NumberStringConverter;
import tabellen.MysqlController;
import tabellen.TabelleKabelzug;
public class mainController {
ObservableList<TabelleKabelzug> oListeKabelzug = FXCollections.observableArrayList();
@FXML
private TableView tableViewKabelzug = new TableView();
@FXML
private TableColumn<TabelleKabelzug, Integer> spalteId = new TableColumn();
@FXML
private TableColumn<TabelleKabelzug, Boolean> spalteIstErledigt = new TableColumn();
@FXML
private TableColumn<TabelleKabelzug, String> spalteTag = new TableColumn();
public void initialize() {
initialisiereKabelzugliste();
tableViewKabelzug.setItems(oListeKabelzug);
}
public void initialisiereKabelzugliste() {
MysqlController controller = new MysqlController();
controller.mitMysqlVerbinden();
oListeKabelzug.setAll(controller.kabelzuglisteLaden());
spalteIstErledigt.setCellFactory(CheckBoxTableCell.forTableColumn(spalteIstErledigt));
spalteTag.setCellFactory(TextFieldTableCell.forTableColumn(spalteTag));
tableViewKabelzug.setItems(oListeKabelzug);
}
}
Example of my TableColumn "spalteTag" within my .fxml-File:
<TableColumn fx:id="spalteTag" text="BMK">
<cellValueFactory>
<PropertyValueFactory property="tag" />
</cellValueFactory>
<cellFactory>
??? <-- Any code in here possible?
</cellFactory>
</TableColumn>
Here is a sample of what it looks like at the moment (without any errors of course): TableView with populated data and Checkboxes
So my 3 questions now are: First how can I add TextFields in every TableView cell that is dedicated to a String value? Second how can I make these TextFields editable for every TableView cell? Third and is there any setup possible for this in my .fxml file? (this would be the most convenient solution to me)
Greetings from Germany :)