Results 1 to 5 of 5

Thread: gridbaglayout

  1. #1
    newtojava7 is offline Member
    Join Date
    Jan 2008
    Posts
    16
    Rep Power
    0

    Default gridbaglayout

    hello,

    i'm using gridbaglayout and finding it very frustrating (must use it for assignment).

    im using the constrains.gridy which is set to 1 right now, i want it to go a bit lower, so i change it to 2, but it makes the component go much lower than I want it to, and if I go say 1.5 it gives me an error when i compile saying "possible loss of precision."

    i just want to move my component a bit lower, i tried GridBagConstraints.SOUTH as well and it has no effect on its location, please help.

  2. #2
    JAdmin is offline Member
    Join Date
    Jan 2008
    Posts
    20
    Rep Power
    0

    Default

    GridBagLayout is the most complex but the most useful layout manager in Swings. When using GridBagLayout, you need to understand GridBagConstraints because the positioning and other aspects like padding etc are adjusted using attributes of this class.

    While gridx and gridy are used to specify the row and column values where the components are placed, there are many other parameters that decide the final look and feel. In your case, you may want to look at the 'insets' because this constraint specifies the expernal padding.

    You can still use gridy as 1 and add some 'inset' (The value is specified as an Insets object - e.g . new Insets(2,2,2,2) ) to the components to give some external padding. You can adjust the values for top, left, bottom, and right insets to give the necessary padding to your component.

    Hope this helps!
    Sincerely, Your friends at www.javaadvice.com

  3. #3
    riz618 is offline Member
    Join Date
    Jan 2008
    Posts
    8
    Rep Power
    0

    Default

    Hey,
    If you simply want to get your component lower you must try to put that component on a panel and then put the panel on top of the container. Let me know if that helps.

    JPanel panel = new JPanel();

  4. #4
    newtojava7 is offline Member
    Join Date
    Jan 2008
    Posts
    16
    Rep Power
    0

    Default

    thanks to you both, will give it a try!

    by the way do you know how to increase and decrease the size of componants in the gridbaglayout?

    edit: riz how can I put a component into a panel?
    Last edited by newtojava7; 01-27-2008 at 07:12 PM.

  5. #5
    riz618 is offline Member
    Join Date
    Jan 2008
    Posts
    8
    Rep Power
    0

    Default

    Container c = getContentPane();
    JPanel NorthPanel = new JPanel();
    c.add(NorthPanel);

    This should do it..

Similar Threads

  1. GridBagLayout
    By newtojava7 in forum New To Java
    Replies: 2
    Last Post: 03-07-2008, 01:16 AM
  2. GridBagLayout...please help
    By newtojava7 in forum Advanced Java
    Replies: 1
    Last Post: 02-17-2008, 02:16 AM
  3. Replies: 1
    Last Post: 02-17-2008, 12:43 AM
  4. Need a idea on GridBagLayout
    By ddsuresh in forum AWT / Swing
    Replies: 1
    Last Post: 01-29-2008, 02:32 AM
  5. Problem with GridBagLayout
    By Daniel in forum SWT / JFace
    Replies: 2
    Last Post: 07-01-2007, 07:57 PM

Posting Permissions

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