在 vaadin 中,如果我将宽度和高度设置为未定义,则在使用 getHeight()/getWidth() 函数时我将得到 -1。 如果我使用 sizeful(),我将得到 100%。但是我怎样才能得到组件的确切宽度和高度呢?
最佳答案
您可以通过调用 javascript 函数来获取回调结果。 在 http://demo.vaadin.com/sampler/#foundation/javascript-callback 中阅读更多内容
像这样的东西:
如果你有 HorizontalLayout h
HorizontalLayout h = new HorizontalLayout()
//...
h.setId("myId");
JavaScript.getCurrent().addFunction("myGetWidth",
new JavaScriptFunction() {
@Override
public void call(final JSONArray arguments)
throws JSONException {
int width = arguments.getInt(0);
//now you can do something with this width
}
});
JavaScript.getCurrent().execute("myGetWidth(document.getElementById('" +h.getId() + "').clientWidth);");
关于html - 在 Vaadin 中获取组件的确切宽度和高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7787649/