I was having the same problem 3 weeks ago, but with TextFields. I used your code and added the part that Henri suggested you, but it shows the same results as yours.
Weirdly , if you change your labels to text fields, it works:
Window main = new Window();
setMainWindow(main);
VerticalLayout Vertical = new VerticalLayout();
main.addComponent(Vertical);
TextField tf1 = new TextField("TF1");
TextField tf2 = new TextField("TF2");
Vertical.addComponent(tf1);
Vertical.addComponent(tf2);
Vertical.setComponentAlignment(tf1, Alignment.BOTTOM_LEFT);
Vertical.setComponentAlignment(tf2, Alignment.TOP_CENTER);
It seems than labels cant be align if they are alone :wacko: There must be a way, but I dont know how.
As Henri pointed out earlier, setting the size of the Label to undefined or fixed size, you can align them like any other component. The default width is just 100% for Labels (and they are of course centered, but by being 100% wide they stretch from side to side).
[quote=
Jouni Koivuviita]
As Henri pointed out earlier, setting the size of the Label to undefined or fixed size, you can align them like any other component. The default width is just 100% for Labels (and they are of course centered, but by being 100% wide they stretch from side to side).
What I’m trying to achieve, is having a Label that would center in its containing VerticalLayout and would be able to wrap, if the text width won’t fit into single line.
Is it possible? AFAIK, to center a label, it must have an undefined size (otherwise it stretches to 100% and even though the label itself is centered, the text in the label isn’t). On the other hand, the label cannot have undefined size, if I want it to wrap the text. Kind of catch-22
is there any solution to this?
This should be doable. You could just try adding a stylename to the the undefined wide label, and override the white-space:nowrap property with CSS (or just use the .v-label-undef-width selector that is added to all labels with undefined width).
The problems start when the containing layout should be able to grow vertically depending on the content of the label (IIRC), but if the size of the label is undefined, some crazy things happen.