Reputation: 35
I know there are many questions about this, but the answers didn't solve my problem.
I have a TableView with 4 columns. The data is read out of a txt file.
In the initialize method from the Controller the CellValueFactory is set, and another method is called, which reads the Data from the file and creates an observableList of the model.
Then the list is added to the items of the table, but no data is displayed, and no placeholder is there. Does anyone know what is wrong?
@FXML
private TableView<Data> dataTable;
@FXML
private TableColumn<Data, String> dataType;
@FXML
private TableColumn<Data, String> dataName;
@FXML
private TableColumn<Data, String> dataDate;
@FXML
private TableColumn<Data, String> dataInformation;
@FXML
public void initialize() {
dataType.setCellValueFactory(value -> new SimpleStringProperty(value.getValue().getDataType()));
dataName.setCellValueFactory(value -> new SimpleStringProperty(value.getValue().getDataName()));
dataDate.setCellValueFactory(value -> new SimpleStringProperty(value.getValue().getDataDate()));
dataInformation.setCellValueFactory(value -> new SimpleStringProperty(value.getValue().getDataInformation()));
initData();
}
private void initData() {
ArrayList<Data> data = new ArrayList<>();
try {
Path filePath = Paths.get("src/main/resources/kl/fla/decrypted.txt");
if (filePath.toFile().exists()) {
data = (ArrayList<Data>) Files.readAllLines(filePath, StandardCharsets.UTF_8).stream()
.map(Data::new).collect(Collectors.toList());
}
} catch (Exception e) {
e.printStackTrace();
}
dataTable.setItems(FXCollections.observableArrayList(data));
dataTable.refresh();
}
<Pane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="720.0"
prefWidth="1080.0" xmlns="http://javafx.com/javafx/18" xmlns:fx="http://javafx.com/fxml/1" fx:controller="kl.fla.controller.TableController"
>
<children>
<Label alignment="CENTER" layoutX="393.0" layoutY="34.0" prefHeight="70.0" prefWidth="295.0" text="Hidden Gate">
<font>
<Font size="48.0" />
</font>
</Label>
<TableView fx:id="dataTable" fixedCellSize="1.0" layoutX="36.0" layoutY="141.0" prefHeight="439.0" prefWidth="840.0">
<columns>
<TableColumn fx:id="dataType" prefWidth="135.0" resizable="false" text="Datatype" />
<TableColumn fx:id="dataName" minWidth="4.0" prefWidth="135.0" resizable="false" text="Name" />
<TableColumn fx:id="dataDate" prefWidth="135.0" resizable="false" text="Date" />
<TableColumn fx:id="dataInformation" minWidth="0.0" prefWidth="285.0" resizable="false" text="Information" />
</columns>
</TableView>
</children>
</Pane>
Upvotes: 0
Views: 87
Reputation: 209339
The data are (probably) there; you just can’t see them because you have constrained every row to be just one pixel high:
fixedCellSize="1.0"
Remove that attribute and just use the default setting, and it should work (assuming there are no other errors in code you haven’t posted).
Upvotes: 3