GridBagLayout and GridBagConstraints Help
Author |
Message |
gsquare567
|
Posted: Tue Jan 23, 2007 7:56 pm Post subject: GridBagLayout and GridBagConstraints Help |
|
|
code: | public GridBagConstraints getConstraints(int gridx, int gridy, int gridwidth, int gridheight,
int ipadx, int ipady, int anchor, int fill)// used to set up component when being added to panel
{
GridBagConstraints c = new GridBagConstraints(); // creates GridBagConstraints object
c.insets = new Insets(5,5,5,5); // sets space around the component
c.gridx = gridx;// sets 'x' coordinate of component on the grid
c.gridy = gridy;// sets 'y' coordinate of component on the grid
c.gridwidth = gridwidth;// sets number of cells component uses going right
c.gridheight = gridheight;// sets number of cells component uses going downwards
c.ipadx = ipadx;// resizes width of component
c.ipady = ipady;// resizes height of component
c.anchor = anchor;// sets alignment of component in cell
c.fill = fill;// sets type of fill for component in cell
return c;// returns the object with these settings
} |
and my use, example:
code: |
general.setLayout(new GridBagLayout());
general.setBorder(BorderFactory.createTitledBorder(loweredBorder, "General"));
general.add(gLabel, getConstraints(0, 0, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE));
general.add(fgTextField, getConstraints(1, 0, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE));
|
that appears as:
---[General]----------------------------------------------------------------------
| [gLabel] [gTextField] |
----------------------------------------------------------------------------------
i want:
---[General]----------------------------------------------------------------------
| [gLabel] [gTextField] |
------------------------------------------------------------------------------------
nothing to do with the insets. i dont know how to change it. |
|
|
|
|
|
Sponsor Sponsor
|
|
|
|
|