I have this small sample code:
Main class:
package sample;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
import java.io.IOException;
public class Main extends Application {
public static void main(String[] args) {
Application.launch(args);
}
@Override
public void start(Stage stage) throws IOException {
stage.setTitle("Tree Table View Samples");
FXMLLoader loader = new FXMLLoader();
Parent sceneRoot = loader.load(getClass().getResource("sample.fxml"));
Controller controller = new Controller();
loader.setController(controller);
final Scene scene = new Scene(sceneRoot, 450, 400);
stage.setScene(scene);
stage.show();
}
}
Controller:
public class Controller {
@FXML private Button btnAdd;
@FXML private Button btnDelete;
@FXML private TreeTableView<String> treeTableView;
@FXML private TreeTableColumn<String, String> columnC1;
public void initialize() {
final TreeItem<String> childNode1 = new TreeItem<>("Child Node 1");
final TreeItem<String> childNode2 = new TreeItem<>("Child Node 2");
final TreeItem<String> childNode3 = new TreeItem<>("Child Node 3");
final TreeItem<String> root = new TreeItem<>("Root node");
root.setExpanded(true);
root.getChildren().setAll(childNode1, childNode2, childNode3);
columnC1.setCellValueFactory((TreeTableColumn.CellDataFeatures<String, String> p) ->
new ReadOnlyStringWrapper(p.getValue().getValue()));
treeTableView.setRoot(root);
treeTableView.setShowRoot(true);
btnAdd.setOnAction(actionEvent -> root.getChildren().add(new TreeItem<>("Another Child")));
btnDelete.setOnAction(actionEvent -> root.getChildren().remove(root.getChildren().size()-1));
}
}
fxml:
<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0"
prefWidth="450.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sample.Controller">
<center>
<TreeTableView fx:id="treeTableView" prefHeight="100.0" prefWidth="430.0" BorderPane.alignment="CENTER">
<columns>
<TreeTableColumn fx:id="columnC1" prefWidth="430.0" text="C1" />
</columns>
</TreeTableView>
</center>
<bottom>
<HBox prefHeight="100.0" prefWidth="200.0" BorderPane.alignment="CENTER">
<children>
<Button fx:id="btnAdd" mnemonicParsing="false" prefHeight="35.0" prefWidth="113.0" text="Add" />
<Button fx:id="btnDelete" mnemonicParsing="false" prefHeight="35.0" prefWidth="95.0" text="Delete" />
</children>
</HBox>
</bottom>
I can add or delete rows, this works fine. But as soon as the scrollbar on the right side appears and I add/delete rows, while the scrollbar is not at the bottom, the TreeTableView content disappears (if there is a second scrollbar at the bottom, the content does not disappear). After scrolling down it appears again, so it is not a terrible bug, but an annoying one.
Has anyone an explanation for this bug or even a solution?
Thanks
EDIT:
Here are the screenshots that sunflame requested:
I am using java 8, jfx 11 my OS is Ubuntu 18.04.5 LTS (Bionic Beaver)