Setting a Row or Column of a GridBadLayout to a Particular Size

By default, the width of a column in a gridbag layout is set to the widest component in the component. This example demonstrates how to increase the width of the column to a particular size. The same applies to rows of a gridbag layout.

See Creating a GridBagLayout for an example on how to use a gridbag layout.

// Sets the minimum width for column c to be w pixels wide public void setColumnMinWidth(GridBagLayout gbl, int c, int w) { int[] ws = gbl.columnWidths; if (ws == null) { ws = new int[c+1]; } else if (ws.length < c+1) { ws = new int[c+1]; System.arraycopy(gbl.columnWidths, 0, ws, 0, gbl.columnWidths.length); } ws[c] = w; gbl.columnWidths = ws; } // Sets the minimum height for row r to be h pixels high public void setRowMinHeight(GridBagLayout gbl, int r, int h) { int[] hs = gbl.rowHeights; if (hs == null) { hs = new int[r+1]; } else if (hs.length < r+1) { hs = new int[r+1]; System.arraycopy(gbl.rowHeights, 0, hs, 0, gbl.rowHeights.length); } hs[r] = h; gbl.rowHeights = hs; }

Post a comment

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image. Ignore spaces and be careful about upper and lower case.