JavaFX The items in the listview are not fully displayed, when the item type is textflow

46 Views Asked by At

I use listview to display some textflow nodes, but when the length of the text in the textflow node is much longer than the length of the listview, these nodes cannot be fully displayed. the jdk version is openjdk 15.0, javafx version is openjfx 15.0.2.

this is a example

import javafx.application.Application;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.control.ListView;
import javafx.scene.text.Text;
import javafx.scene.text.TextFlow;
import javafx.stage.Stage;

public class App extends Application {

    @Override
    public void start(Stage primaryStage) throws Exception {

        ListView<Node> lv = new ListView<>();
        for (int i = 0; i < 10; i++) {
            // long text
            TextFlow tf = new TextFlow(new Text("aaaaa...aaaa"));
            lv.getItems().add(tf);
        }
        primaryStage.setScene(new Scene(lv,600,400));
        primaryStage.show();

    }

}

and I got:

normal

At this point, everything is normal.

When I reduce the window width:

abnormal

it cannot display all items.

At this point, the lower part of the listview cannot be clicked, and the white and gray background of the original listview will not be displayed. I once tried to put textflow into the stackpane, but still encountered this problem.

I know shortening the width of the textflow can solve this problem, but I want to know how to solve this problem without shortening the width of the textflow. and I also want to know what caused this problem.

0

There are 0 best solutions below