MagOnline
MagOnline

Reputation: 23

How to reduce with of vertical Text / Label

I want to place a vertical (90 degree rotated) Label on the left side of a HBox. A grid pane shall fill out the entire remaining space. If I decrease the with of the rotated label to reduce its requirred horizontal space, the text length is shrinked. Otherwise if i reduce the Height manually, nothing happens.

How can i reduce the used with of the rotated Label?

Using Scenebuilder and Windows 7.

Upvotes: 0

Views: 890

Answers (1)

James_D
James_D

Reputation: 209330

Rotate the Label and wrap it in a Group. The layout bounds of the group will be computed after applying the transformation to the label:

import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;

public class RotatedLabelTest extends Application {

    @Override
    public void start(Stage primaryStage) {
        Label hello = new Label("Hello");
        Label world = new Label("World");
        hello.setRotate(90);
        world.setRotate(90);
        HBox root = new HBox(5, new Group(hello), new Group(world));

        primaryStage.setScene(new Scene(root));
        primaryStage.show();
    }

    public static void main(String[] args) {
        launch(args);
    }
}

Upvotes: 5

Related Questions