how to leave space between components in BoxLayout

Discussion in 'Java' started by alex_us01, Sep 30, 2005.

  1. alex_us01

    alex_us01 Guest

    hello,

    I wonder how to leave space between components in a vertical BoxLayout.

    Something like:

    ==========
    BoxLayout boxLayout = new BoxLayout(this, BoxLayout.Y_AXIS);
    myPanel.setLayout(boxLayout);
    ....
    myPanel.add(new JLabel("first label");
    myPanel.add(new JLabel("second label");
    ==========

    I want to leave a vertical space between labels.

    thanks,
    alex
    alex_us01, Sep 30, 2005
    #1
    1. Advertising

  2. "alex_us01" <> wrote:
    > I wonder how to leave space between components in a vertical BoxLayout.
    >
    > Something like:
    >
    > ==========
    > BoxLayout boxLayout = new BoxLayout(this, BoxLayout.Y_AXIS);
    > myPanel.setLayout(boxLayout);
    > ...
    > myPanel.add(new JLabel("first label");

    myPanel.add(new Box.Filler(....));
    > myPanel.add(new JLabel("second label");
    > ==========
    >
    > I want to leave a vertical space between labels.

    class Box.Filler (in package javax.swing) was invented just for this
    purpose.

    --
    "TFritsch$t-online:de".replace(':','.').replace('$','@')
    Thomas Fritsch, Sep 30, 2005
    #2
    1. Advertising

  3. alex_us01

    Paul Tomblin Guest

    In a previous article, "alex_us01" <> said:
    >==========
    >BoxLayout boxLayout = new BoxLayout(this, BoxLayout.Y_AXIS);
    >myPanel.setLayout(boxLayout);
    >...
    >myPanel.add(new JLabel("first label");

    myPanel.add(Box.createVerticalStrut(5));
    >myPanel.add(new JLabel("second label");
    >==========



    --
    Paul Tomblin <> http://xcski.com/blogs/pt/
    Q: How did you get into artificial intelligence?
    A: Seemed logical -- I didn't have any real intelligence.
    Paul Tomblin, Sep 30, 2005
    #3
  4. alex_us01

    Roedy Green Guest

    On 29 Sep 2005 17:54:23 -0700, "alex_us01" <> wrote
    or quoted :

    >I want to leave a vertical space between labels.

    there is always the kludge of the dummy label.

    You can also use GridBagLayout where you can play with insets or other
    tweakers to get the spacing you want.
    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Again taking new Java programming contracts.
    Roedy Green, Sep 30, 2005
    #4
  5. > BoxLayout boxLayout = new BoxLayout(this, BoxLayout.Y_AXIS);
    > myPanel.setLayout(boxLayout);
    > ...
    > myPanel.add(new JLabel("first label");
    > myPanel.add(new JLabel("second label");
    > ==========
    >
    > I want to leave a vertical space between labels.


    RainLayout is much better than BoxLayout.

    With RainLayout you can:
    - easy switch between horizontal and vertical orientation
    - Components can be layed out in one row or in multiple rows
    - ordering of Components according to Comparator provided by target
    Container
    - row hiding: show only one row and hide all other rows
    - easy reverse Components and/or rows order
    and of course
    - set horizontal and vertical gap between components

    Component resizing behavior can be specified with 4 constraints:
    - RainLayout.GROW (Component can grow),
    - RainLayout.SHRINK (Component can shrink),
    - RainLayout.FLEX (Component can shrink and grow) and
    - RainLayout.FIXED

    see http://jgui.imagero.com/rainLayout.html

    the only disadvantage of RainLayout - it is not free.

    --
    Andrey Kuznetsov
    http://uio.imagero.com Unified I/O for Java
    http://reader.imagero.com Java image reader
    http://jgui.imagero.com Java GUI components and utilities
    Andrey Kuznetsov, Sep 30, 2005
    #5
  6. alex_us01

    Roedy Green Guest

    On Fri, 30 Sep 2005 09:53:08 +0200, "Andrey Kuznetsov"
    <> wrote or quoted :

    >RainLayout is much better than BoxLayout.


    Why is it called RainLayout? I could not see the connection.
    see http://mindprod.com/jgloss/layout.html
    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Again taking new Java programming contracts.
    Roedy Green, Sep 30, 2005
    #6
  7. Andrey Kuznetsov, Sep 30, 2005
    #7
  8. Andrey Kuznetsov wrote:
    >>>RainLayout is much better than BoxLayout.

    >>
    >>Why is it called RainLayout? I could not see the connection.
    >>see http://mindprod.com/jgloss/layout.html

    >
    >
    > no connection ;-)
    > If you have idea for better name, tell me please, I will rename it.


    ShineLayout? ( still no connection, but nicer ..and shinier ;)
    Andrew Thompson, Sep 30, 2005
    #8
  9. Andrey Kuznetsov, Sep 30, 2005
    #9
  10. alex_us01

    Roedy Green Guest

    On Fri, 30 Sep 2005 12:15:53 +0200, "Andrey Kuznetsov"
    <> wrote or quoted :

    >If you have idea for better name, tell me please, I will rename it.


    It is a nice name. I just could not see how its behaviour was related
    to rain.
    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Again taking new Java programming contracts.
    Roedy Green, Oct 1, 2005
    #10
    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. ben
    Replies:
    2
    Views:
    357
  2. Shuo Xiang

    Stack space, global space, heap space

    Shuo Xiang, Jul 9, 2003, in forum: C Programming
    Replies:
    10
    Views:
    2,855
    Bryan Bullard
    Jul 11, 2003
  3. Christian Seberino
    Replies:
    21
    Views:
    1,620
    Stephen Horne
    Oct 27, 2003
  4. Ian Bicking
    Replies:
    2
    Views:
    975
    Steve Lamb
    Oct 23, 2003
  5. Ian Bicking
    Replies:
    2
    Views:
    702
    Michael Hudson
    Oct 24, 2003
Loading...

Share This Page