Label inside a Panel

Hello,

At the moment, I’m experimenting a bit with the UI components.
When I set a caption on a label that’s added to a Layoutcomponent, the caption is shown as expected.
But when I wrap that label in a panel first, the caption is never shown.

I’ve tested with several other components and their captions seem to work perfectly.
Is there a reason why labels inside panels cannot have a caption?
Or is this some kind of bug?

Kind regards,

Ken Wouters

Bonjour,
which version of Vaadin do you use ?
Because I put labels in panels and the caption is visible.
I never faced this issue.

à bientôt,

I have tested it in version 7.0.6 & 7.1.0.beta1 and the caption isn’t shown in either version.

Could you post some code with which you can reproduce the problem?

This should reproduce the problem.


package com.example.labelpaneltest;

import com.vaadin.server.VaadinRequest;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Label;
import com.vaadin.ui.Panel;
import com.vaadin.ui.UI;
import com.vaadin.ui.VerticalLayout;

/**
 * Main UI class
 */
@SuppressWarnings("serial")
public class LabelpaneltestUI extends UI {

	private VerticalLayout mainLayout;

	@Override
	protected void init(VaadinRequest request) {
		mainLayout = new VerticalLayout();
		
		Label label = new Label();
		label.setValue("This is the value");
		label.setCaption("caption");
		
		
		Panel panel = new Panel();
		panel.setContent(label);
		
		mainLayout.addComponent(panel);
		
		
		setContent(mainLayout);
	}


}

This is a “feature”. In Vaadin, excluding a few special cases such as Button, a component’s caption is handled by its parent component. Panel never displays the caption of its content component; you should either set the caption of the Panel, or if you want the caption inside the Panel, wrap your content in a layout (preferably CssLayout as it has the least overhead).

The limitation made more sense in Vaadin 6 where the content of a panel had to be a layout or other component container, and those rarely have captions.

Allright, makes sense.
Thank you for the clear answer and for your time!

Thats right.
in vaadin 6, I was able to add components directly into the panel using th addComponent method.
in vaadin 7, you used the setContent method to put your label directly into the panel, and the label’s caption is hidden.
Of course, you may create a layout, set the content of your panel to this layout and add your labels into the layout.