Hello!
I've got a problem. Please look at the code below. When I use rigidarea to
spearate buttons, no matter how large is the frame, buttons are separated
properly. But when I use vertical and horizontal struts vertical space
between buttons is changing along with the frame size. What is the reason?
Thanks for any help.
import java.awt.*;
import javax.swing.*;
public class klasa {
public static void main(String[] args) {
Ramka r = new Ramka();
r.setSize(200,200);
r.pack();
r.setVisible(true);
}
}
class Ramka extends JFrame {
public Ramka() {
Container c = this.getContentPane();
Box L1 = Box.createHorizontalBox();
Box L2 = Box.createHorizontalBox();
Box L = Box.createVerticalBox();
L1.add(new JButton("test1"));
//L1.add(Box.createRigidArea(new Dimension(5,0)));
L1.add(Box.createHorizontalStrut(10));
L1.add(new JButton("test2"));
L1.setAlignmentX(Component.LEFT_ALIGNMENT);
L2.add(new JButton("test3"));
//L2.add(Box.createRigidArea(new Dimension(5,0)));
L2.add(Box.createHorizontalStrut(10));
L2.add(new JButton("test4"));
L2.setAlignmentX(Component.LEFT_ALIGNMENT);
L.add(L1);
//L.add(Box.createRigidArea(new Dimension(0,5)));
L.add(Box.createVerticalStrut(10));
L.add(L2);
c.add(L);
}
}
--
M.
Bart Cremers - 26 Sep 2006 09:56 GMT
> Hello!
>
[quoted text clipped - 8 lines]
> --
> M.
Struts have unlimited maximum heights or widths (for horizontal and
vertical struts, respectively). This means that if you use a horizontal
box within a vertical box, for example, the horizontal box can
sometimes become too tall. For this reason, it's recommend that you
use rigid areas instead of struts.
Regards,
Bart