在vaadin中,如果我将宽度和高度设置为未定义,那么在使用getHeight()/getWidth()函数时我将得到-1。
如果我使用 sizeful(),我会得到 100%。但是如何获得组件的准确宽度和高度呢?
您可以通过调用 javascript 函数并获取回调结果来完成此操作。
阅读更多内容http://demo.vaadin.com/sampler/#foundation/javascript-callback 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);");
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)