Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Viewing GridBagLayout's Grid Lines?

Reply
Thread Tools

Viewing GridBagLayout's Grid Lines?

 
 
John Davison
Guest
Posts: n/a
 
      12-09-2003
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?

-- John
 
Reply With Quote
 
 
 
 
Chris Smith
Guest
Posts: n/a
 
      12-10-2003
John Davison wrote:
> 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?


One trick I have used in the past, especially when teaching, is to set
controls to different background colors. That makes the exact
boundaries between controls on the screen precisely visible. Not
exactly what you wanted, but it might help...

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
Reply With Quote
 
 
 
 
Sandip Chitale
Guest
Posts: n/a
 
      12-10-2003
One technique may be:

For each of your component added to the GridBagLayout

Modify its contraint fill=BOTH
Replace it with a JLabel with a line border.
The JLabels label could show the name of original component.

Just a thought.

http://www.velocityreviews.com/forums/(E-Mail Removed) (John Davison) wrote in message news:<(E-Mail Removed). com>...
> 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?
>
> -- John

 
Reply With Quote
 
Karsten Lentzsch
Guest
Posts: n/a
 
      12-10-2003
John Davison wrote:

> 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?


The JGoodies Forms layout system ships with a debug panel
that provides different options to paint the FormLayout grid,
see http://www.jgoodies.com/freeware/formsdemo/index.html

The code is open source and it should be no big deal
to translate it to the GridBagLayout. Both layout managers
use a LayoutInfo object that comprises the actual grid data.

Forms ships with a second debug class, FormDebugUtils,
that I find useful too. It dumps a lot of information about
the layout manager state, its grid, the components and
their associated constraints. This class could be converted
to GridBagLayout too.

You can download the Forms distribution including sources
from JavaDesktop.org where the project is maintained, see
the file sharing section at http://forms.dev.java.net/
If you convert these classes to GridBagLayout I should
appreciate if you would send me the code, so I can include
it with the Forms distribution.

Also, you may consider given FormLayout a try. It has been
designed to overcome shortcomings in the GridBagLayout.

Best regards,
--
Karsten Lentzsch
www.JGoodies.com - Java User Interface Design


 
Reply With Quote
 
Todd Corley
Guest
Posts: n/a
 
      12-10-2003
"Karsten Lentzsch" <(E-Mail Removed)> wrote in message news:<br65t2$bnn$03$(E-Mail Removed)-online.com>...
> John Davison wrote:
>
> > 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;
}
 
Reply With Quote
 
Tor Iver Wilhelmsen
Guest
Posts: n/a
 
      12-10-2003
(E-Mail Removed) (John Davison) writes:

> 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?


Some bean tools/GUI designers do - like JBuilder from Borland.
 
Reply With Quote
 
Todd Corley
Guest
Posts: n/a
 
      12-10-2003
(E-Mail Removed) (Todd Corley) wrote in message news:<(E-Mail Removed). com>...
> "Karsten Lentzsch" <(E-Mail Removed)> wrote in message news:<br65t2$bnn$03$(E-Mail Removed)-online.com>...
> > John Davison wrote:
> >
> > > 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;
> }


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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Grouped grid? Or grid within datalist? Danny Tuppeny ASP .Net 1 10-27-2005 10:03 PM
How to transfer a value from an Invisible Grid to an visible Grid =?Utf-8?B?QXNzYW5LaGFuIElzbWFpbA==?= ASP .Net 2 10-17-2005 03:56 AM
Grid within a Grid ItemDataBound event problem Girish ASP .Net 4 07-19-2005 01:17 AM
PC Viewing vs DVD Player Viewing - MP3 play very fast Ray Donzdorf Computer Support 0 12-11-2004 01:07 PM
Grid question: How do I force grid elements to expand and use available space Marc Python 0 10-08-2003 05:06 PM



Advertisments