TreeItem resizing when resizing

I would like to create a TreeView with only a vertical scrollbar, so if I reduce the width of the window, the content should be wrapped, and the TreeView should increase their height.

My idea is to make FlowPane - TreeItem as a child.

I try this code in a very different combination

FlowPane flowPane = new FlowPane();        
flowPane.setMaxWidth(Double.MAX_VALUE);
flowPane.setPrefWidth(200.0f);
flowPane.setMinWidth(100.0f);
flowPane.setMaxHeight(Double.MAX_VALUE);
flowPane.getChildren().addAll( /* add many childs which should be wrapped */ );
TreeItem<FlowPane > = new TreeItem<FlowPane>(flowPane);

when I reduce the width, the children in the FlowPane are wrapped, but the container does not increase the height. He looks squeezed.

Any ideas how to solve this problem?

How to make a TreeItem that wrapped content and increased height when resized?

UPDATE: I solve this by adding a listener to the scene

scene.widthProperty().addListener( new ChangeListener<Number>() {
        @Override
        public void changed(ObservableValue<? extends Number> arg0, Number arg1,    Number arg2) {
           MainController.handleOnResize();
        }
    });

Then I repeat ListView and update height if ListItem has FlowPane as value

if (treeItem.getValue() instanceof FlowPane) {
final FlowPane flowPane = (FlowPane) treeItem.getValue();

                    Task task = new Task<Void>() {

                        @Override
                        public Void call() {
                            int i = 0;
                            while (flowPane.getHeight() == 0.0) {
                                if (++i > 2) {
                                    return null;
                                }

                                try {
                                    Thread.sleep(500);
                                } catch (InterruptedException ex) {
                                }

                            }
                            flowPane.setPrefHeight(flowPane.getHeight() + flowPane.getChildren().size() * 0.95);

                            return null;
                        }
                    };


                    new Thread(task).start();

. flowPane.getHeight() - ,

+3

All Articles