Label CSS style problem

Hello guys,

Im facing a really strange problem right now. Let me cut to the chase. I have a really simple horizontal layout with a label on it.

In my css file, there is a following style:


.helloLabel {
    color: white;
}

And here we are. There are 2 scenarios:

  1. This one works perfectly. The css style is injected succesfully.

Label myLabel = new Label("Hello");
myLabel.addStyleName("helloLabel");
  1. This one doesn’t work. The css style isnt injected at all.

Label myLabel = new Label();
myLabel.setCaption("Hello");
myLabel.addStyleName("helloLabel");

And the only difference between those examples is that the caption is set later(not in the constructor).

Thank you in advance.

Regards, Satrix

I think you want to do setValue() instead of setCaption(). Caption is a field of AbstractComponent and is displayed above (by default) each component, if set.

Thank you Philippe. It works now. But I have one more question. I want to do the same thing with Textfield caption. In my css file I have defined style like this:


.v-textfield-caption-loginTF {
    font: bold;
}

But it doesnt work. Any idea why ?

Regards, Satrix

If I add setStyleName(“TFNb”) to one of my text fields, I see it has two (well three) classes: v-caption and v-caption-TFNb (Vaadin 6.7.1, Chameleon theme if it is relevant (but I doubt it)).
A sub-div has also v-captiontext class (that’s the third one), unaffected by setStyleName.

You need to use valid CSS. Bold is set with font-weight, not font.