2014-02-16 43 views
1

這是我編寫的代碼,但寬度未設置爲VBox項目。我得到所有面板相同的大小。我需要一些幫助。 在此先感謝!寬度是不是爲javafx VBox項目設置?

private void initComponents() { 
    this.setPadding(new Insets(0,70,0,70)); 
    this.setSpacing(10); 

    red1 = new StackPane(); 
    red1.setStyle("-fx-background-color:red;"); 
    red1.setPrefHeight(60); 
    red1.setPrefWidth(260); 
    this.setVgrow(red1, Priority.ALWAYS); 
    this.getChildren().add(red1); 
    red2 = new StackPane(); 
    red2.setStyle("-fx-background-color:red;"); 
    red2.setPrefHeight(60); 
    red2.setPrefWidth(240); 
    this.setVgrow(red2, Priority.ALWAYS); 
    this.getChildren().add(red2); 

} 

private StackPane red1; 
private StackPane red2; 
} 

回答

1

如果可能的話,所有窗格都會嘗試佈局並調整其子項的大小,並且所有窗格均由其父母通過尊重其內容來調整大小。閱讀javadoc以獲取更多信息。

所有窗格(VBoxStackPaneFlowPanePane等)被封裝到javafx.​scene.​layout包,這意味着這些窗格用於敷設其他節點/控制。

您實際試圖獲得的形狀被打包到javafx.​scene.​shape包中。使用它們,例如:

red1.getChildren().add(new Rectangle(200, 100, Color.YELLOW)); 
... 
red2.getChildren().add(new Circle(30, Color.BLUE)); 
+0

它的工作原理,thanx! – JanithOCoder

相關問題