import javafx.application.Application; import javafx.event.EventHandler; import javafx.geometry.Pos; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.control.Label; import javafx.scene.input.MouseEvent; import javafx.scene.layout.GridPane; import javafx.stage.Stage; /** * * @author Alexander Kouznetsov */ public class LayoutTest extends Application{ @Override public void start(Stage primaryStage) { final Label label = new Label("This is label"); label.setStyle("-fx-background-color: red;"); label.setAlignment(Pos.CENTER_RIGHT); label.setRotate(-90); final Group group = new Group(label); final GridPane pane = new GridPane(); // Try different layouts here // HBox.setHgrow(label, Priority.ALWAYS); pane.getChildren().setAll(group); pane.setGridLinesVisible(true); // Scene scene = new Scene(group); Scene scene = new Scene(pane, 500, 500); primaryStage.setScene(scene); primaryStage.setVisible(true); label.addEventHandler(MouseEvent.MOUSE_CLICKED, new EventHandler() { public void handle(MouseEvent event) { label.setText(label.getText() + " +1"); System.out.println("label.layoutBounds = " + label.getLayoutBounds()); System.out.println("label.getWidth() = " + label.getWidth() + ", label.getMinWidth() = " + label.getMinWidth()); System.out.println("group.layoutBounds = " + group.getLayoutBounds()); label.setMinWidth(label.getWidth() + 10); label.setMinHeight(label.getHeight() + 10); // group.requestLayout(); // pane.requestLayout(); } }); } public static void main(String[] args) { launch(args); } }