-2

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 :)

Vitt3x
  • 1
  • work through tutorials on a) how to use fxml b) how to use tableView/-Column - at the very least read and understand the api doc of classes/methods you are using. Your code is fundamentally wrong in many places, f.i. manually creating fields that are annotated for fxml injection, instantiating a controller that's meant to be loaded (a bit guesssing here), incorrect method calls (as noted in the answer and the compile error you are seeing :), violating java naming conventions .. – kleopatra Mar 17 '21 at 12:43

1 Answers1

0

You don't have to pass parameter to forTableColumn function. Try this

spalteTag.setCellFactory(TextFieldTableCell.forTableColumn());