Field | Purpose |
---|---|
gridx | column number. First column is column 0. It is ok to skip columns to leave room to add stuff later. They won’t take up space. |
gridy | row number. Top row is row 0. It is ok to skip rows. |
gridwidth | How many cells wide the Component is. May not be 0. This is not the number of pixels, but rather the number of cells. It can look as though nothing is happening if you increase the gridwidth for all the cells in a column since the extra column is zero-width. Rows must have different gridwidths in some cell for you to notice any difference between rows in cell size. |
gridheight | How many cells tall the Component is. May not be 0. |
weightx | What percentage of the extra width in the container should this Component take for its growth? Percentages don’t have to add up to 100. GridBagLayout normalises them for you, I have heard some talk what it does is actually more complicated. Note these are not the percentages for width, but the percentages for sharing the pie of any excess width left over after every column gets its minimum. Only cells using FILL will partake of the growth. |
weightx | What percentage of the extra height in the container should this Component take for its growth? Percentages don’t have to add up to 100. |
anchor | Where you want your Component to rest in its containing box. By default it is GridBagConstraints. CENTER. possibilities are: CENTER, NORTH, NORTHEAST, EAST, SOUTHEAST, SOUTH, SOUTHWEST, WEST and NORTHWEST. |
fill | GridBagConstraints.NONE = don’t grow the Component even if its allotted space is bigger than he Component. VERTICAL=grow the Component vertically to take up extra height. HORIZONTAL=grow the Component horizontally to take up extra width. BOTH=grow both vertically and horizontally. |
ipadx | How much wider you want your Component to be than it would be normally. Measured in pixels. |
ipady | How much taller you want your Component to be than it would be normally. Measured in pixels. |
insets | new Insets ( /* top */ 0 , /* left */ 0 , /* bottom */ 0 , /* right */ 0 ) The minimum amount of white space you demand around your Component. Measured in pixels. |
If your GridBagLayout does not work, here are some things to check:
// Applet Gridbag: // 0 1 2 // --------title--- about 0 // --------raw---------- 1 // -------cooked-------- 2 // Charset Clear Convert 3 // target 4 // trim 5 // -----instructions----- 6
this.setLayout( gridBagLayout ); this.add( aButton, constraints );becomes:
Container contentPane = this.getContentPane(); contentPane.setLayout( gridBagLayout ); contentPane.add( aButton, constraints );People complained so much about this clumsy syntax that in Java version 1.5 or later you can now do your setLayout directly on the JApplet again if you choose.
This page is posted |
http://mindprod.com/jgloss/gridbaglayout.html | |
Optional Replicator mirror
|
J:\mindprod\jgloss\gridbaglayout.html | |
Please read the feedback from other visitors,
or send your own feedback about the site. Contact Roedy. Please feel free to link to this page without explicit permission. | ||
Canadian
Mind
Products
IP:[65.110.21.43] Your face IP:[18.118.193.20] |
| |
Feedback |
You are visitor number | |