Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / December 2003

Tip: Looking for answers? Try searching our database.

Viewing GridBagLayout's Grid Lines?

Thread view: 
John Davison - 09 Dec 2003 22:09 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
visible?

-- John
Chris Smith - 10 Dec 2003 02:23 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
> 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...

Signature

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

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation

Sandip Chitale - 10 Dec 2003 02:46 GMT
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.

> 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
Karsten Lentzsch - 10 Dec 2003 04:02 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
> 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
Todd Corley - 10 Dec 2003 15:45 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
> > 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
Tor Iver Wilhelmsen - 10 Dec 2003 21:14 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
> visible?

Some bean tools/GUI designers do - like JBuilder from Borland.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.