2016-12-11 10 views

答えて

2

は、私の知る限り、これを行う方法はありませんが、あなたはGridPane

private static void setBackground(Region region, Color color) { 
    region.setBackground(new Background(new BackgroundFill(color, CornerRadii.EMPTY, Insets.EMPTY))); 
} 

@Override 
public void start(Stage primaryStage) { 
    GridPane gridPane = new GridPane(); 
    RowConstraints rConstranits1 = new RowConstraints(); 
    rConstranits1.setVgrow(Priority.NEVER); 
    RowConstraints rConstranits2 = new RowConstraints(); 
    rConstranits2.setVgrow(Priority.ALWAYS); 
    RowConstraints rConstranits3 = new RowConstraints(); 
    rConstranits3.setVgrow(Priority.NEVER); 

    ColumnConstraints cConstraints1 = new ColumnConstraints(); 
    cConstraints1.setHgrow(Priority.NEVER); 
    ColumnConstraints cConstraints2 = new ColumnConstraints(); 
    cConstraints2.setHgrow(Priority.ALWAYS); 
    ColumnConstraints cConstraints3 = new ColumnConstraints(); 
    cConstraints3.setHgrow(Priority.NEVER); 

    gridPane.getColumnConstraints().addAll(cConstraints1, cConstraints2, cConstraints3); 
    gridPane.getRowConstraints().addAll(rConstranits1, rConstranits2, rConstranits3); 

    Region top = new Region(); 
    top.setPrefSize(300, 100); 
    setBackground(top, Color.RED); 

    Region bottom = new Region(); 
    bottom.setPrefSize(400, 50); 
    setBackground(bottom, Color.YELLOW); 

    Region center = new Region(); 
    setBackground(center, Color.BLUE); 

    Region right = new Region(); 
    setBackground(right, Color.LIME); 
    right.setPrefSize(200, 500); 

    Region left = new Region(); 
    setBackground(left, Color.BROWN); 
    left.setPrefSize(200, 400); 

    gridPane.add(right, 2, 0, 1, 3); 
    cConstraints3.maxWidthProperty().bind(right.prefWidthProperty()); 
    cConstraints3.minWidthProperty().bind(right.prefWidthProperty()); 
    gridPane.add(top, 0, 0, 2, 1); 
    rConstranits1.minHeightProperty().bind(top.prefHeightProperty()); 
    rConstranits1.maxHeightProperty().bind(top.prefHeightProperty()); 
    gridPane.add(bottom, 0, 2, 2, 1); 
    rConstranits3.minHeightProperty().bind(bottom.prefHeightProperty()); 
    rConstranits3.maxHeightProperty().bind(bottom.prefHeightProperty()); 
    gridPane.add(center, 1, 1); 
    gridPane.add(left, 0, 1); 
    cConstraints1.minWidthProperty().bind(left.prefWidthProperty()); 
    cConstraints1.maxWidthProperty().bind(left.prefWidthProperty()); 

    Scene scene = new Scene(gridPane); 

    primaryStage.setScene(scene); 
    primaryStage.show(); 
} 
1

ネスト2 BorderPanesを使用して所望の結果を達成することができますことは、その後BorderPaneの高さに建てられ&幅管理に依存している別のオプションです。例ベースとsetBackgroundルーチンのためのファビアンへの信用!

private static void setBackground(Region region, Color color) { 
    region.setBackground(new Background(new BackgroundFill(color, CornerRadii.EMPTY, Insets.EMPTY))); 
} 

@Override 
public void start(Stage primaryStage) { 

    BorderPane outer = new BorderPane(); 
    BorderPane inner = new BorderPane(); 

    Region top = new Region(); 
    top.setPrefSize(300, 300); 
    setBackground(top, Color.RED); 

    Region bottom = new Region(); 
    bottom.setPrefSize(400, 200); 
    setBackground(bottom, Color.YELLOW); 

    Region right = new Region(); 
    setBackground(right, Color.BLUE); 
    right.setPrefSize(200, 500); 

    inner.setCenter(top); 
    inner.setBottom(bottom); 

    outer.setCenter(inner); 
    outer.setRight(right); 

    Scene s = new Scene(outer); 
    primaryStage.setScene(s); 
    primaryStage.show(); 

} 
+0

これはより洗練された方法だと思います(他の回答のコンストレイントの負荷を参照)。本当に私を助けました!どうもありがとう :) – geisterfurz007

関連する問題