Hello
is there any way how to get Vaadin component Width and Height to server-side?
Maybe whole position rect?
I need that because of drawing.
Thanks Miloš
Hello
is there any way how to get Vaadin component Width and Height to server-side?
Maybe whole position rect?
I need that because of drawing.
Thanks Miloš
You will need to use either JavaScript or an add-on. The
SizeReporter
does exactly that.
-Olli
The SizeReporter doesn’t have a version for Vaadin 8, so if you’re using 8, here’s a small example of using JavaScript to get the absolute pixel position of a component with defined id of ‘componentId’. It’s rather hacky, and I don’t recommend using these kind of things unless absolutely necessary:
JavaScriptFunction foo = new JavaScriptFunction() {
@Override
public void call(JsonArray arguments) {
JreJsonNumber top = arguments.get(0);
}
}
JavaScript.getCurrent().addFunction("getAbsoluteTop", foo);
JavaScript.getCurrent()
.execute("getAbsoluteRop(document.getElementById('componentId')
.offsetTop);");
Paddings and margins can affect this, so you have to be careful. Hope this helps! Discussion and possible alternative solutions at
https://stackoverflow.com/questions/7787649/get-the-exactly-width-and-height-of-a-component-in-vaadin
BR, Katri