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);
}
}