n列とGridPane
n行のaがあり、各セルにaがあります(ほとんどチェス盤のようです)。sを拡張して、拡張しすぎずに、各セルで使用可能なすべてのスペースを占有しようとしています。アプローチを試しましたが、 sの幅を何にバインドするかまだわかりません。Rectangle
Rectangle
ColumnConstraints
Rectangle
解決策:Rectangle
幅と高さをにバインドしNumberBinding
ます。
例、チェス盤を作成します。
GridPane board = new GridPane();
NumberBinding rectsAreaSize = Bindings.min(board.heightProperty(), board.widthProperty());
for(int i = 0; i < size; ++i)
{
for(int j = 0; j < size; ++j)
{
Rectangle rect;
if(i % 2 == 0 ^ j % 2 == 0) // ^ is the XOR operator
{
rect = new Rectangle(15.0, 15.0, Color.WHITE);
}
else
{
rect = new Rectangle(15.0, 15.0, Color.BLACK);
}
rect.widthProperty().bind(rectsAreaSize.divide(size));
rect.heightProperty().bind(rectsAreaSize.divide(size));
board.add(rect, i, j);
GridPane.setHalignment(rect, HPos.CENTER);
}
}
参照: