Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > how to leave space between components in BoxLayout

Reply
Thread Tools

how to leave space between components in BoxLayout

 
 
alex_us01
Guest
Posts: n/a
 
      09-30-2005
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

 
Reply With Quote
 
 
 
 
Thomas Fritsch
Guest
Posts: n/a
 
      09-30-2005
"alex_us01" <(E-Mail Removed)> 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('$','@')


 
Reply With Quote
 
 
 
 
Paul Tomblin
Guest
Posts: n/a
 
      09-30-2005
In a previous article, "alex_us01" <(E-Mail Removed)> 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 <(E-Mail Removed)> http://xcski.com/blogs/pt/
Q: How did you get into artificial intelligence?
A: Seemed logical -- I didn't have any real intelligence.
 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      09-30-2005
On 29 Sep 2005 17:54:23 -0700, "alex_us01" <(E-Mail Removed)> 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.
 
Reply With Quote
 
Andrey Kuznetsov
Guest
Posts: n/a
 
      09-30-2005
> 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


 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      09-30-2005
On Fri, 30 Sep 2005 09:53:08 +0200, "Andrey Kuznetsov"
<(E-Mail Removed)> 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.
 
Reply With Quote
 
Andrey Kuznetsov
Guest
Posts: n/a
 
      09-30-2005
>>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.

--
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


 
Reply With Quote
 
Andrew Thompson
Guest
Posts: n/a
 
      09-30-2005
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
 
Reply With Quote
 
Andrey Kuznetsov
Guest
Posts: n/a
 
      09-30-2005
> ShineLayout? ( still no connection, but nicer ..and shinier



--
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


 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      10-01-2005
On Fri, 30 Sep 2005 12:15:53 +0200, "Andrey Kuznetsov"
<(E-Mail Removed)> 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
vertical BoxLayout, JLabel, and JButton and alignment Duane Evenson Java 5 09-27-2007 07:33 PM
Alignment in Swing-BoxLayout Christian Otteneuer Java 0 07-08-2006 01:44 PM
Box, Boxlayout problem Sean Anderson Java 3 05-15-2005 12:36 AM
BoxLayout bug in 1.5? Ryan Stewart Java 10 03-02-2005 02:52 AM
COM components referenced in asp.net leave SQL connections open ben ASP .Net 2 07-01-2004 09:53 PM



Advertisments