Please suggest a layout manager

Discussion in 'Java' started by On Ali, Feb 17, 2007.

  1. On Ali

    On Ali Guest

    Hi,

    Can anyone suggest a layout manager which would do the following:

    - Stack the components one below the other (Not the way CardLayout
    does, but like a grid layout with 1 column)
    - Set the width of each component as that of the panel (minus insets)
    - Set the height as the preferred height

    The behavior I want is similar to the windows explorer details panel
    on the left. (Some blocks can be opened or closed using arrow buttons)

    Thanks in advance,

    Regards,
    On Ali
    On Ali, Feb 17, 2007
    #1
    1. Advertising

  2. On Ali

    Eric Sosman Guest

    On Ali wrote:
    > Hi,
    >
    > Can anyone suggest a layout manager which would do the following:
    >
    > - Stack the components one below the other (Not the way CardLayout
    > does, but like a grid layout with 1 column)
    > - Set the width of each component as that of the panel (minus insets)
    > - Set the height as the preferred height


    Perhaps you want BoxLayout with a vertical orientation?

    > The behavior I want is similar to the windows explorer details panel
    > on the left. (Some blocks can be opened or closed using arrow buttons)


    When you change the size of an already-painted component,
    you'll probably need to re-pack() the container to inform the
    layout manager of the change.

    --
    Eric Sosman
    lid
    Eric Sosman, Feb 17, 2007
    #2
    1. Advertising

  3. On Ali

    On Ali Guest

    On Feb 17, 6:56 pm, Eric Sosman <> wrote:
    > On Ali wrote:
    > > Hi,

    >
    > > Can anyone suggest a layout manager which would do the following:

    >
    > > - Stack the components one below the other (Not the way CardLayout
    > > does, but like a grid layout with 1 column)
    > > - Set the width of each component as that of the panel (minus insets)
    > > - Set the height as the preferred height

    >
    > Perhaps you want BoxLayout with a vertical orientation?
    >
    > > The behavior I want is similar to the windows explorer details panel
    > > on the left. (Some blocks can be opened or closed using arrow buttons)

    >
    > When you change the size of an already-painted component,
    > you'll probably need to re-pack() the container to inform the
    > layout manager of the change.
    >
    > --
    > Eric Sosman
    >


    i am not very sure whether the box layout fulfills my second and third
    requirements
    On Ali, Feb 17, 2007
    #3
  4. On Ali

    Eric Sosman Guest

    On Ali wrote:
    > On Feb 17, 6:56 pm, Eric Sosman <> wrote:
    >> On Ali wrote:
    >>> Hi,
    >>> Can anyone suggest a layout manager which would do the following:
    >>> - Stack the components one below the other (Not the way CardLayout
    >>> does, but like a grid layout with 1 column)
    >>> - Set the width of each component as that of the panel (minus insets)
    >>> - Set the height as the preferred height

    >> Perhaps you want BoxLayout with a vertical orientation?

    >
    > i am not very sure whether the box layout fulfills my second and third
    > requirements


    It does -- or so it seems to me; I may have misunderstood
    your requirements. Why not try it for yourself?

    --
    Eric Sosman
    lid
    Eric Sosman, Feb 17, 2007
    #4
  5. On Ali

    On Ali Guest

    On Feb 17, 7:24 pm, Eric Sosman <> wrote:
    > On Ali wrote:
    > > On Feb 17, 6:56 pm, Eric Sosman <> wrote:
    > >> On Ali wrote:
    > >>> Hi,
    > >>> Can anyone suggest a layout manager which would do the following:
    > >>> - Stack the components one below the other (Not the way CardLayout
    > >>> does, but like a grid layout with 1 column)
    > >>> - Set the width of each component as that of the panel (minus insets)
    > >>> - Set the height as the preferred height
    > >> Perhaps you want BoxLayout with a vertical orientation?

    >
    > > i am not very sure whether the box layout fulfills my second and third
    > > requirements

    >
    > It does -- or so it seems to me; I may have misunderstood
    > your requirements. Why not try it for yourself?
    >
    > --
    > Eric Sosman
    >


    i have actually seen the screenshots on the sun site.... i takes the
    preferred width of the component and not the total available width of
    the container
    On Ali, Feb 17, 2007
    #5
  6. On Ali

    Guest

    On 17 Feb., 15:12, "On Ali" <> wrote:
    > On Feb 17, 6:56 pm, Eric Sosman <> wrote:
    > i am not very sure whether the box layout fulfills my second and third
    > requirements


    Why don't you try it?
    , Feb 17, 2007
    #6
  7. "On Ali" <> wrote in message
    news:...
    > i am not very sure whether the box layout fulfills my second and third
    > requirements


    It depends on what you mean by the second one. For
    a vertical orientation I believe it will make all the
    components the same width, if they aren't restricted by
    maximum width. If it's a column of buttons for example,
    they will all be as wide as the largest preferred width.

    If the panel is on one side of a split pane or something
    and you want the components to fill the width of the
    panel but for the panel still to have a meaningful
    preferred width, then GridBagLayout would be easy
    enough, or you could write your own layout to do this
    in about ten minutes. For the simplest case (minimum
    size == preferred size, tightly packed components,
    align to top, no respect for maximum sizes) you could
    do something like (untested, may contain errors):

    public Dimension preferredLayoutSize(Container parent) {
    Component[] children = parent.getComponents();
    Dimension psize = new Dimension();
    for(int c = 0; c < children.length; c++) {
    Dimension child_psize = children[c].getPreferredSize();
    psize.height += child_psize.height;
    psize.width = Math.max(psize.width, child_psize.width); }
    Insets insets = parent.getInsets();
    psize.width += insets.left + insets.right;
    psize.height += insets.top + insets.bottom;
    return psize;
    }

    public Dimension minimumLayoutSize(Container parent) {
    return preferredLayoutSize(parent);
    }

    public void layoutContainer(Container parent) {
    Dimension msize = minimumLayoutSize(parent);
    Insets insets = parent.getInsets();
    int w = Math.max(parent.getSize().width, msize.width) -
    insets.left - insets.right;
    int x = insets.left;
    int y = insets.top;
    Component[] children = parent.getComponents();
    for(int c = 0; c < children.length; c++) {
    Component child = children[c];
    Dimension child_psize = child.getPreferredSize();
    child.setLocation(x, y);
    child.setSize(w, child_psize.height);
    y += child_psize.height;
    }
    }

    public void addLayoutComponent(String name,
    Component comp) {
    }

    public void removeLayoutComponent(Component comp) {
    }
    Larry Barowski, Feb 17, 2007
    #7
  8. On Ali schrieb:
    > The behavior I want is similar to the windows explorer details panel
    > on the left. (Some blocks can be opened or closed using arrow buttons)


    Hi,

    it looks as if SwingLabs (http://swinglabs.org/) JXTaskPane does what
    you want.

    Yours,

    Alexander
    Alexander Schoelling, Feb 17, 2007
    #8
  9. On Ali

    On Ali Guest

    On Feb 18, 12:13 am, Alexander Schoelling <>
    wrote:
    > On Ali schrieb:
    >
    > > The behavior I want is similar to the windows explorer details panel
    > > on the left. (Some blocks can be opened or closed using arrow buttons)

    >
    > Hi,
    >
    > it looks as if SwingLabs (http://swinglabs.org/) JXTaskPane does what
    > you want.
    >
    > Yours,
    >
    > Alexander


    this is nice..! thank you
    On Ali, Feb 19, 2007
    #9
    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. Frédéric Colombero

    how do I can get values from layout Manager

    Frédéric Colombero, Nov 3, 2003, in forum: Java
    Replies:
    2
    Views:
    384
    Frédéric Colombero
    Nov 5, 2003
  2. Replies:
    1
    Views:
    572
    John Timney \(MVP\)
    Jun 19, 2006
  3. Replies:
    13
    Views:
    806
  4. padma
    Replies:
    0
    Views:
    345
    padma
    Oct 3, 2007
  5. Metalone
    Replies:
    0
    Views:
    342
    Metalone
    Jan 6, 2010
Loading...

Share This Page