我有一個簡單的問題。網格能否自動調整其中的對象以適應網格?Gridpane可以自動調整其對象的大小嗎?嘗試將max_width和max_height設置爲網格並使其調整內容大小。 JavaFX
我想在網格上設置max_height和max_width以及最小寬度和最小高度,並在我的窗口中居中該網格。
在我的網格中,我想在所有位置添加Spacer Square。每個墊片都有邊框。所以它看起來像一個實際的網格。
如果我的網格是4x4,我想那裏有16個大方格。
如果我的網格是16x18,我想那裏有288個方格。
這兩個選項都應占用一定數量的區域,288平方選項的方格比16選項小很多,以適合我的網格尺寸。
我檢查了gridpane文檔,但如果對我有選項,我很困惑。我不知道填充,邊距,setmaxwidth,setmaxheight(試過這個,沒有改變一件事)之間的區別。
double dimension_x=100; //max_width of actual square/spacer/gridspace
double dimension_y=100; //max_height of actual square/spacer/gridspace
int grid_x=100; //number of rows
int grid_y=100; //number of columns
Rectangle[][] rectangles = new Rectangle[grid_x][grid_y];
GridPane grid = new GridPane();
double grid_max_x=800;
double grid_max_y=600;
grid.setHgap(1);
grid.setVgap(1);
grid.setPadding(new Insets(16)); //not sure what this does. Attempt Fail
grid.setEffect(addEffect(Color.web("#202C2F"), .61, 12));
grid.setMaxHeight(grid_max_y); //does nothing that it APPEARS to me
for (int x=0;x<grid_x;x++)
{
for(int y=0;y<grid_y;y++)
{
Rectangle temp = new Rectangle(dimension_x,dimension_y);
grid.add(temp,x,y);
}
}
我希望能使用網格來放置網格列下的png圖像。使用網格可以讓我輕鬆地保存png圖像。有沒有辦法做到這一點與網格? – CREW 2012-03-23 00:40:48