Label in Vaadin framework

In this tutorial, we will learn together about Label object in Vaadin!

To be clear, I’ve created a Vaadin project using the Vaadin plugin in Eclipse:

Label in Vaadin framework

You do not know how to create a project, so you can refer to this tutorial!

OK, let’s get started!

First, remove all the code contained in the init() method of the MyUI class.

The Label in Vaadin is the object that when generated it will be the <label> tag in HTML, used to display some text. We can initialize the Label object and display it as follows:

Result:

Label in Vaadin framework

In addition, we can also have other operations with the Label object as follows:

Edit text:

Result:

Label in Vaadin framework

  • We can define Label with regular text by declaring ContentMode.TEXT:

Result:

Label in Vaadin framework

  • Or as text formatted ContentMode.PREFORMATTED:

Result:

Label in Vaadin framework

  • Or as an HTML ContentMode.HTML:

Result:

Label in Vaadin framework

  • By default, the width and height of a label is 100%, but you can also use the setWidth() and setHeight() methods of Label to set its width and height.

Result:

Label in Vaadin framework
Here are the basic operations of Label in Vaadin, you can further explore by using the Label object above, enter “label.” then Ctrl + Space 😀

Add Comment