Viewing GridBagLayout's Grid Lines?

Discussion in 'Java' started by John Davison, Dec 9, 2003.

  1. John Davison

    John Davison Guest

    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
     
    John Davison, Dec 9, 2003
    #1
    1. Advertising

  2. John Davison

    Chris Smith Guest

    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
     
    Chris Smith, Dec 10, 2003
    #2
    1. Advertising

  3. 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.

    (John Davison) wrote in message news:<>...
    > 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
     
    Sandip Chitale, Dec 10, 2003
    #3
  4. 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
     
    Karsten Lentzsch, Dec 10, 2003
    #4
  5. John Davison

    Todd Corley Guest

    "Karsten Lentzsch" <> wrote in message news:<br65t2$bnn$03$-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;
    }
     
    Todd Corley, Dec 10, 2003
    #5
  6. (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.
     
    Tor Iver Wilhelmsen, Dec 10, 2003
    #6
  7. John Davison

    Todd Corley Guest

    (Todd Corley) wrote in message news:<>...
    > "Karsten Lentzsch" <> wrote in message news:<br65t2$bnn$03$-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
     
    Todd Corley, Dec 10, 2003
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Passero

    grid or gridbaglayout

    Passero, Jul 2, 2003, in forum: Java
    Replies:
    3
    Views:
    3,131
    dhek bhun kho
    Jul 2, 2003
  2. me
    Replies:
    2
    Views:
    4,558
    Sudsy
    Jul 21, 2003
  3. David McCallum

    GridBagLayout Example

    David McCallum, Oct 23, 2003, in forum: Java
    Replies:
    0
    Views:
    704
    David McCallum
    Oct 23, 2003
  4. AJ
    Replies:
    6
    Views:
    732
  5. KingKongBundy

    Using GridBagLayout with JFrame

    KingKongBundy, Aug 24, 2004, in forum: Java
    Replies:
    7
    Views:
    5,597
    KingKongBundy
    Aug 25, 2004
Loading...

Share This Page