0

I have a VBox in a Dialog/DialogPane, and a child Group (groupB) wrapping a Group (groupA) of Shapes. groupA is too big for the screen, so I add a Scale transform to groupB to bring it down to size, and that works perfectly. Except that the window seems to think that the Node is still huge, and the dialog stretches far beyond the bounds of the screen. The parent bounds seem to change after the Scale is applied, but not the layout bounds. How do I scale a Group so that it affects the layout?

Edit: I just wrote up a concise illustration of the problem with an Eclipse project hosted on BitBucket: http://v.gd/0trUMv

You can click the toggle button to switch between big and small. Note that the transformation is applied before the Group is added. Toggling to a large circle shows that the layout is considering the full dimensions of the child node. The question is how to override that behavior without changing the properties of the child node. The desired behavior is to have the layout bounds encompass only the small circle.

2nd Edit: here is the code in-line.

import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.VBox;
import javafx.scene.shape.Circle;
import javafx.scene.shape.Shape;
import javafx.scene.transform.Scale;
import javafx.scene.transform.Transform;
import javafx.stage.Stage;

public class Demo extends Application {

    private Scene scene = null;
    private static final String mksml = "make small";
    private static final String mkbig = "make big";
    private static final Transform smallScale = new Scale(0.2, 0.2);

    @Override
    public void start(Stage primaryStage) throws Exception {
        Shape bigGraphic = new Circle(500);
        Group originalBigGroup = new Group(bigGraphic);
        Group transformedGroup = new Group(originalBigGroup);
        transformedGroup.getTransforms().add(smallScale);
        Button xformToggle = new Button(mkbig);
        xformToggle.setOnMouseClicked((MouseEvent mouseEvent) -> {
            switch(xformToggle.getText()) {
            case mkbig:
                transformedGroup.getTransforms().clear();
                xformToggle.setText(mksml);
                break;
            case mksml:
                transformedGroup.getTransforms().add(smallScale);
                xformToggle.setText(mkbig);
            }
        });
        VBox layout = new VBox(xformToggle, transformedGroup);
        scene = new Scene(layout);
        primaryStage.setScene(scene);
        primaryStage.show();
    }

    public static void main(String[] args) {
        Application.launch(args);
    }
}
Travis Well
  • 947
  • 10
  • 32

1 Answers1

0

Something like this, Group does not to position or organise its children hence if it starts of as 1000*1000 it will end up with 1000*1000 unless you explicitly reduce it. Hence the VBox stays the same and you get the same dimension

Does it fit?

Elltz
  • 10,730
  • 4
  • 31
  • 59
  • Elltz, true, Group would not change the dimensions of child nodes. That's why there should be a difference between bounds in local and bounds in parent. I'm not sure what you're suggesting could be a fix though. I should not have to change the dimensions of the child to change the dimensions of the parent, or else I would say the scene graph has a bug. – Travis Well Oct 18 '15 at 21:06