我需要在屏幕上渲染小部件后获取其宽度,因为当我在附加小部件后尝试获取其宽度时,它会返回零。我最早什么时候可以检索到小部件的有效偏移宽度?
提前致谢!
最佳答案
只有在浏览器构建页面内容后才知道框的偏移宽度。使用scheduleDefferred()
,即可获取该值。
示例:
final TextBox yourInput = new TextBox();
Scheduler.get().scheduleDeferred(new ScheduledCommand() {
@Override
public void execute() {
int width = yourInput.getOffsetWidth();
/* Do anything with width */
}
});
关于gwt getOffsetWidth 返回零,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7747433/