[英]JavaFX StackPane bounds not updated
當我運行以下程序時
import javafx.application.Application;
import javafx.application.Platform;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.Pane;
import javafx.scene.layout.StackPane;
import javafx.scene.shape.Ellipse;
import javafx.stage.Stage;
public class Test1 extends Application {
public static void main(String[] args) throws Exception {
launch(args);
}
@Override
public void start(Stage stage) throws Exception {
Pane topPane = new Pane();
Scene scene = new Scene(topPane, 600, 400);
StackPane sp = new StackPane();
Label l1 = new Label("1 2");
Ellipse e1 = new Ellipse(100, 50);
e1.setOpacity(0.5);
sp.getChildren().addAll(l1, e1);
e1.radiusXProperty().bind(l1.widthProperty());
e1.radiusYProperty().bind(l1.heightProperty());
topPane.getChildren().add(sp);
sp.relocate(200, 100);
sp.setStyle("-fx-border-color: RED;");
Platform.runLater(() -> {
//l1.setText("123");
//l1.setText("1 2");
});
stage.setScene(scene);
stage.show();
}
}
我只得到一個圍繞文本標簽的紅色框,但是當我取消注釋上面的Platform.runLater()塊內的兩條線時,我得到一個圍繞外部橢圓的紅色框,這就是我想要的。 所以在我看來,堆棧窗格的布局邊界沒有從模型描述中正確設置,因為邊界僅由標簽控件確定。 但是當我在Platform.runLater()中強制失效時,布局邊界應該是它們的位置。
為什么會發生這種情況,我該如何預防呢? 我希望能夠只指定我的模型/圖形然后它應該在第一個節目上正確呈現,或者?
添加這個sp.requestLayout();
after stage.Show();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.