Results 1 to 7 of 7
Like Tree4Likes
  • 1 Post By DarrylBurke
  • 1 Post By radish
  • 2 Post By camickr

Thread: Layout Managers

  1. #1
    radish is offline Member
    Join Date
    Aug 2013
    Posts
    16
    Rep Power
    0

    Default Layout Managers

    Finally got around to having a play with Swing... What i'm after achieving is to keep a fixed width panel on the left for input components and another panel on the right which resizes according to what's available...

    Currently i'm using GridBagLayout, I honestly don't know if that'd the best Layout Manager to use in this instance?

    Java Code:
            f.setLayout(new GridBagLayout());
            
            MyPanel p = new MyPanel();
            MyPanel2 p2 = new MyPanel2();
            p2.p = p;
            
            GridBagConstraints c = new GridBagConstraints();
            c.fill = GridBagConstraints.BOTH;
            c.gridx = 0;
            c.gridy = 0;
            c.gridwidth = 1;
            c.weightx = 0.2;
            c.weighty = 1.0;
            f.add(p2, c);
            
            c.fill = GridBagConstraints.BOTH;
            c.gridx = 1;
            c.gridy = 0;
            c.gridwidth = 300;
            c.weightx = 1.0;
            c.weighty = 1.0;
            f.add(p, c);
    For the rest of the code i'm simply using the refined redSquare demo, but i've sort of duplicated the MyPanel and filled it with different components.
    Refining the Design (The Java™ Tutorials > Creating a GUI With JFC/Swing > Performing Custom Painting)

  2. #2
    radish is offline Member
    Join Date
    Aug 2013
    Posts
    16
    Rep Power
    0

    Default Re: Layout Managers

    Think I should have waited... think the following for the first panel solves it... but pancakes await...
    Java Code:
    c.weightx = 0;

  3. #3
    radish is offline Member
    Join Date
    Aug 2013
    Posts
    16
    Rep Power
    0

    Default Re: Layout Managers

    Ok so that didn't quite do what I wanted...

    Basically I had a list of single items vertically in the left pane, now that I try to make them go two by two it squashes them...

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,234
    Rep Power
    19

    Default Re: Layout Managers

    Moved from New to Java.

    You don't have to use a single layout manager, you know. You can nest containers and each can have a different layout.

    db
    radish likes this.
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  5. #5
    radish is offline Member
    Join Date
    Aug 2013
    Posts
    16
    Rep Power
    0

    Default Re: Layout Managers

    Cheers for the move ;)

    Yes last night I got better results by putting each set in its own panel then putting within other panels...
    DarrylBurke likes this.

  6. #6
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,236
    Rep Power
    7

    Default Re: Layout Managers

    What i'm after achieving is to keep a fixed width panel on the left for input components and another panel on the right which resizes according to what's available...
    I would start with a BorderLayout. Put one panel in the WEST for the fixed width and another panel in the CENTER for the variable.
    gimbal2 and radish like this.

  7. #7
    radish is offline Member
    Join Date
    Aug 2013
    Posts
    16
    Rep Power
    0

    Default Re: Layout Managers

    Quote Originally Posted by camickr View Post
    I would start with a BorderLayout. Put one panel in the WEST for the fixed width and another panel in the CENTER for the variable.
    Likes it, this is also where I finished last night ;)

Similar Threads

  1. Help with layout managers
    By garrym in forum AWT / Swing
    Replies: 2
    Last Post: 12-20-2011, 01:53 AM
  2. trouble with layout managers
    By yemista in forum AWT / Swing
    Replies: 3
    Last Post: 10-27-2011, 07:02 PM
  3. Why use layout managers in applet?
    By Splat in forum New To Java
    Replies: 2
    Last Post: 10-14-2009, 04:41 AM
  4. Multiple Layout Managers
    By AJG in forum New To Java
    Replies: 0
    Last Post: 04-06-2008, 01:43 AM
  5. Layout Managers
    By gmioannou in forum AWT / Swing
    Replies: 1
    Last Post: 12-24-2007, 04:12 AM

Posting Permissions

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