GridBagLayoutProblem
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: GridBagLayoutProblem

  1. #1
    Join Date
    Dec 2008
    Posts
    2

    Question GridBagLayoutProblem

    I started making a small dictionary app for practice but i'm stuck at
    the very beginning . I just don't know how to reduce the space between the
    Container and the first Component that i add, the more i resize the
    window the space is larger. I tried setting the weightx and weighty
    constraints, but still no change. Any help?
    I'v attached the source code and screenshot.

    I want the JTextField component to be the first in right after the window bar with a very small amount of space.
    Attached Images Attached Images  
    Attached Files Attached Files

  2. #2
    Join Date
    May 2006
    Location
    UK
    Posts
    4,473

    Re: GridBagLayoutProblem

    To add space around a component use the ipadx and ipady values.

    Having said that, using GridBagLayout for such a simple problem seems like an over kill to me. Have you looked at the Box container which uses BoxLayout and has methods for adding fixed size invisible components (struts).

  3. #3
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163

    Re: GridBagLayoutProblem

    You could give the main panel a BorderLayout and add your two components to a sub-panel which you then add to the NORTH of the main panel:
    Code:
    ...
    panel.setLayout(new BorderLayout());
    JPanel panelNorth = new JPanel();
    panel.add(panelNorth, BorderLayout.NORTH);
    rec = new JTextField(16);
    potrazi = new JButton("Potrazi");
    panelNorth.add(rec);
    panelNorth.add(potrazi);
    ...
    This will guarantee they always stay at the top.

    If you plan to throw one away, you will throw away two...
    C. Zerouni
    Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

  4. #4
    Join Date
    May 2006
    Location
    UK
    Posts
    4,473

    Re: GridBagLayoutProblem

    Oops, just realised I misread the question, I thought the OP was trying to add space between the components.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center