Important Notice - Forums is archived
To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
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-
Sure:
GridLayout layout = new GridLayout();
... add components into the layout ...
GridLayout.Area area = layout.getComponentArea(theComponent);
int x = area.getColumn1();
int y = area.getRow1();
Alejandro Duarte: Sure:
GridLayout layout = new GridLayout(); ... add components into the layout ... GridLayout.Area area = layout.getComponentArea(theComponent); int x = area.getColumn1(); int y = area.getRow1();
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