4

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: It works until here Than the content disappears until I scroll With JFX 15 even scrolling is leaving a mess

I am using java 8, jfx 11 my OS is Ubuntu 18.04.5 LTS (Bionic Beaver)

  • 2
    Note the `Controller controller = new Controller(); loader.setController(controller);` is unnecessary and most likely has no effect. An instance was already created for you due to the `fx:controller` attribute in the FXML file. – Slaw Dec 15 '20 at 22:55
  • 1
    What do you mean exactly by content disappears? I have tested your code and it works for me fine. I can add/delete rows without any problem so the rows/text do not disappear. Can you explain it or show it with a screenshot? – Sunflame Dec 16 '20 at 09:08
  • Hmm.. worksforme (fx15+, and leaving out the fxml stuff, it's just a simple treeTable with a button :) - maybe a bug in an earlier version (though can't remember anything like your description), or: are you sure that this exact code reproduces it? – kleopatra Dec 16 '20 at 11:44
  • @kleopatra yes, without the fxml it works, but it doesn't with it. So I guess the problem can be somewhere in the communication between fxml, controller and the other stuff. But I did not find anything – PupsGesicht Dec 17 '20 at 08:32
  • if it doesn't work, it doesn't for both direct UI implementation and fxml :) And indeed seems to be an old issue that's fixed recently: misbehaves for fx11, all fine for fx15. So if you can, update your version. Two comments: 1) why java8 and fx11? mixing versions sounds like asking for trouble. 2) setting the controller after the fxml is loaded is .. weird, what do you expect to achieve? – kleopatra Dec 17 '20 at 11:19
  • 2
    found an issue that might be related: https://bugs.openjdk.java.net/browse/JDK-8244826 - that one is implicitly fixed for fx15+ (that is current dev) by a fix in VirtualFlow. The sympton (blank viewport) is the same, just the means to get there is different (here adding, there collapsing) – kleopatra Dec 17 '20 at 11:35
  • 1
    related to your link is this link: https://bugs.openjdk.java.net/browse/JDK-8252811 and that looks like it could be the reason for my problem. So hopefully this will be fixed in jfx 16 – PupsGesicht Dec 17 '20 at 12:04
  • stumble again across this (unrelated) comment _2) setting the controller after the fxml is loaded is .. weird_ - missed that you are using the static load method: that's wrong if you would want access to the controller in some way because your (local loader instance) != (loader used to load the ui) – kleopatra Feb 23 '21 at 10:56
  • Does this answer your question? [TreeTableView items disappear when scroll down and double-click last expand/collapse arrow](https://stackoverflow.com/questions/63836998/treetableview-items-disappear-when-scroll-down-and-double-click-last-expand-coll) – Oboe Dec 16 '21 at 22:24

0 Answers0