> > It would be very helpful when doing layouts with GridBagLayout
> > if I could see the grid lines. Is there a way to make the grid lines
> > visible?
If you consolidate your layout code into a method, you can do some
neat things like the following that adds a titled border to all added
comps that includes the general GBC info. The titled border will add
a line around the components as well, showing the boundries of
everything.
public static Component set(Container cont, JComponent comp,
int x, int y, int w, int h,
double wx, double wy,
int top, int left, int bottom, int
right,
int fill, int anchor)
{
GridBagLayout gbl = getLayout( cont );
clearGridBagConstraints();
gbc.fill = fill;
gbc.gridx = x;
gbc.gridy = y;
gbc.gridwidth = w;
gbc.gridheight = h;
gbc.weightx = wx;
gbc.weighty = wy;
gbc.insets = setInsets(ins, top, left, bottom, right);
gbc.anchor = anchor;
comp.setBorder( BorderFactory.createCompoundBorder(
BorderFactory.createTitledBorder(
"x="+x+
" y="+y+
" w="+w+
" h="+h ) ),
comp.getBorder() ) );
cont.add(comp, gbc);
return comp;
}
Todd Corley - 10 Dec 2003 22:03 GMT
> > > It would be very helpful when doing layouts with GridBagLayout
> > > if I could see the grid lines. Is there a way to make the grid lines
[quoted text clipped - 34 lines]
> return comp;
> }
Woops, I copied this from some of my existing code and left some stuff
dangeling.
gbc is a static GridBagConstraints.
getBorder( Component comp ) is another static method that gets the
GridBagLayout from the component or does some additional setup if the
current layout is not a GBL.
Hope this helps,
Todd