0

I have a quite complex scene graph which has led me to some resizing problems. I'd be glad if you could help me solve it.

My root node is a BorderPane that its center is filled with a ListView. Each cell of the ListView is filled with a customized zoomable ScrollPane as below:

public class ZoomableScrollPane extends ScrollPane {

    Group zoomGroup;
    Scale scaleTransform;
    LineChart<Number , Number> content;
    double scaleValue = 1.0;
    double delta = 0.1;

    public ZoomableScrollPane(LineChart<Number , Number> content, double height) {
        this.content = content;
        this.setPrefHeight(height);
        Group contentGroup = new Group();
        zoomGroup = new Group();
        contentGroup.getChildren().add(zoomGroup);
        zoomGroup.getChildren().add(content);
        setContent(contentGroup);
        scaleTransform = new Scale(scaleValue, scaleValue, 0, 0);
        zoomGroup.getTransforms().add(scaleTransform);

    } 
}

As you can see there is a LineChart inside of each ZoomableScrollPane. I want to do two things with this chart. Firstly, to somehow bind its width with the root layout to get the desired result in case of resizing the window (not zooming, zooming is OK), and secondly to change the chart's width at run time whenever a button is pressed:

public void handleButton(ActionEvent actionEvent) {
     MainController.lineChart1.setPrefWidth(MainController.lineChart1.getPrefWidth() + CONSTANT);
}

The problem is that here I face a conflict. Cause the LineChart is the child of a Group (not a pane), I just know one way of resizability and that is to bind its width manually with the root BorderPane's like this:

MainController.lineChart1.prefWidthProperty().bind(fourChannels.widthProperty().subtract(40));

And in that case, I cannot change the LineChart's width at run time and will get A bound value cannot be set Exception.

I guess one solution could be revising the ZoomableScrollPane class to somehow avoid the need of manual binding, but really have no idea how to do it.

Any help on this would be greatly appreciated.

Zahra E
  • 427
  • 1
  • 6
  • 25
  • Duplicate of: [JavaFX correct scaling](http://stackoverflow.com/questions/16680295/javafx-correct-scaling)? – jewelsea Dec 08 '16 at 18:50
  • @jewelsea It's not about scaling at all. Just don't know how to have an auto resizing Group or how to increase a bound width at run time. – Zahra E Dec 09 '16 at 07:54

1 Answers1

0

You can detect if a property is bound and then unbind it before manipulating it:

if (content.prefWidthProperty().isBound()) {
    content.prefWidthProperty().unbind();
}
...

Presumably when you are zoomed in on a chart and the window is resized the content will already be larger than the viewport, so a forced change in width shouldn't kick in until the window is resized beyond the zoomed in size of the chart?

Given the different conditions you have you might be better off monitoring the size of the BorderPane/ListView and when that changes adjust the size of the charts that need it.

Geoff
  • 568
  • 4
  • 11