Zeezl
Zeezl

Reputation: 133

How can I have one element align to the left and another one centered in Vaadin HorizontalLayout?

I wanna center my Label component in Horizontal Layout (I'm working on navigation bar) but I still want to have hamburger menu button aligned to the left side of the screen, just like that

I tried to use

navbar.setComponentAlignment(myLabel, Alignment.MIDDLE_CENTER);

on my Horizontal Layout but this don't work, it only center in verticaly,

like this:

What can I do to achive that?

Upvotes: 1

Views: 327

Answers (1)

Henri Kerola
Henri Kerola

Reputation: 4967

Vaadin Label is by default 100% wide, so you need to set its width to undefined to center it:

myLabel.setWidthUndefined();

Of course, your HorizontalLayout must be 100% wide (it's undefined by default).

Upvotes: 2

Related Questions