html - 在 Vaadin 中获取组件的确切宽度和高度

标签 html css vaadin

在 vaadin 中,如果我将宽度和高度设置为未定义,则在使用 getHeight()/getWidth() 函数时我将得到 -1。 如果我使用 sizeful(),我将得到 100%。但是我怎样才能得到组件的确切宽度和高度呢?

最佳答案

您可以通过调用 javascript 函数来获取回调结果。 在 http://demo.vaadin.com/sampler/#foundation/javascript-callback 中阅读更多内容

像这样的东西:

如果你有 Horizo​​ntalLayout 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/

相关文章:

javascript - Picasa:自动更改站点中的图像大小

html - Bootstrap Down 向下菜单按钮颜色

android - 用户更改方向后,网站无法正确显示全屏背景

javascript - 如何在javascript中删除特定的dom表

javascript - 改变壁厚铯

html - 将 DIV 拉伸(stretch)到页面底部,上面有一个元素

html - 我不知道如何更改文本在表单文本区域字段中的流动方式?

java - UI.init() 方法中的 setLocation()

java - Vaadin + Spring Boot 中的自定义 servlet

java - vaadin 8 FilesystemContainer 替代方案