Label setSizeFull Vertical Alignment


I want to put labels in gridLayout with Horizontal and Vertical Aligment and each label must be full size.

If I use setComponentAlignment(label, Alignment.MIDDLE_CENTER) and label.setSizeUndefined() it’s OK → see screen1.png

If I use setComponentAlignment(label, Alignment.MIDDLE_CENTER) and label.setSizeFull() it’s KO → see screen1.png

In my screens, Grid Background is blue, Cells Background is red and Labels background is white.

Have you some ideas ?



if you set full size to the Label (or any component), it will occupy all the space available to it. In this case it means that the Label will occupy the whole cell of your GridLayout, and the alignment has no effect anymore.

What is the end result you want to achieve, and why do you need to enable the full height also?



During a click event on a grid cell, the label content in this cell should be updated with a new String or deleted with a empty String.
For this, I used a
on my grid and i get the label with a
( (Label) event.getChildComponent() )

The problem is that if the label is not full size, the user can easily launch a NullPointerException with a click in the red area next to the white label. And if I catch the NullPointerException, the user don’t understand why the label is not updated…

The best way would be to retrieve the coordinates of the clicked cell on the grid and make a
getComponent (XCell, yCell)
but I do not know if it’s possible.


I found a solution to get the clicked cell of a GridLayout :

public void layoutClick(LayoutClickEvent event) {

    // I divide the x position of the clicked event ([i]
[/i]) by the number of columns ([i]
[/i]) and the total width of the grid ([i]
    int coordX = (int) (event.getRelativeX() / (grid.getWidth() / cols));

    // The same with the y position
    int coordY = (int) (event.getRelativeY() / (grid/getHeight() / rows));

    // I change the value of the (coordX , coordY) label of the grid
    ((Label) getComponent(coordX, coordY)).setValue("309 158 125 145");