Work with GridLayout

Hello, I need your help.
I work with GridLayout with some columns and rows. Each slot of GridLayout contains HorizontalLayout with button.
Is the method, which will return number of column and row, where I pressed button?

You can use this method:
https://vaadin.com/api/com/vaadin/ui/GridLayout.html#getComponentArea-com.vaadin.ui.Component-

Give me example, please, how it use

Sure:

GridLayout layout = new GridLayout();

... add components into the layout ...

GridLayout.Area area = layout.getComponentArea(theComponent);
int x = area.getColumn1();
int y = area.getRow1();

Thank you :slight_smile:

I’m sorry, but it doesn’t work for me(
This code will work if add theComponent(it is my button) in slot gridlayout, but in slot i add horizontallayout, in horizontallayout I add theComponent. And if I add your code, i’ll get exception in line 5 'cause theComponet belongs to horizontallayout, not to slot of gridlayout. Help me, please, how I can return number of column and row of slot, where I pressed button?

Hi,

you should be able to get the HorizontalLayout that holds the Button by theComponent.getParent(), which you can then use in line 5 of the above example instead of theComponent.

Hope this helps,
Olli

Thanks, a lot!