how to leave space between components in BoxLayout

A

alex_us01

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
 
T

Thomas Fritsch

alex_us01 said:
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.
 
P

Paul Tomblin

In a previous article 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");
==========
 
R

Roedy Green

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

Andrey Kuznetsov

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

Andrew Thompson

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

ShineLayout? ( still no connection, but nicer ..and shinier ;)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top