Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Centering a label

867289Jul 2 2011 — edited Jul 3 2011
Hi,

I am trying to center a text in a label, but when I am setting alignment to Pos.CENTER or set for label -fx-alignment: CENTER in css - the label is still on the left side.
In javafx 1.3 there was a layoutInfo property, but in 2.0 there is no such property. Any ideas?

Btw, here is my code (in groovy):
class FxApp extends Application {

    /**
     * @param args the command line arguments
     */
    static void main(String[] args) {
		Application.launch(FxApp.class, args);
    }
	
    @Override
    public void start(Stage primaryStage) {
		primaryStage.setTitle("Hello World");

		Region root = new Region();
		def scene = new Scene(root, 300, 250, Color.rgb(242, 242, 242));

		Label lbl = new Label(
			text: "Test",
			alignment: Pos.CENTER,
			height: 250,
			width: 300
		)
		
		root.getChildren().add(lbl)
		
        primaryStage.setScene(scene);
        primaryStage.setVisible(true);

		
    }
}
ndrw
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 31 2011
Added on Jul 2 2011
1 comment
874 views