Problem getting Label width
ytwApr 18 2012 — edited Apr 19 2012Hello,
I can't get a Label's width with the following test code.
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class GetLabelWidthTest extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception {
primaryStage.setTitle("Label width test");
StackPane sp = new StackPane();
Label label = new Label();
label.setText("test");
sp.getChildren().add(label);
double width = label.getWidth();
System.out.println(width); // always prints 0
Scene scene = new Scene(sp, 800, 600);
primaryStage.setScene(scene);
primaryStage.show();
}
}
Does anyone know why?
Thanks for your help.