为什么SWT Composite有时需要调用resize()才能正确布局? [英] Why does an SWT Composite sometimes require a call to resize() to layout correctly?

查看:205
本文介绍了为什么SWT Composite有时需要调用resize()才能正确布局?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有时我们会遇到一个绝对拒绝正确摆脱的SWT复合材料。当我们在复合材料上调用dispose然后用另一个替换它时,我们经常会遇到这种情况;虽然它似乎并不严格限于这种情况。

Sometimes we encounter an SWT composite that absolutely refuses to lay itself out correctly. Often we encounter this when we have called dispose on a composite, and then replaced it with another; although it does not seem to be strictly limited to this case.

当我们遇到这个问题时,大约50%的时间,我们可以调用 pack() layout()关于违规复合材料,一切都会好的。但是,大约50%的时间我们必须这样做:

When we run into this problem, about 50 % of the time, we can call pack() and layout() on the offending composite, and all will be well. About 50 % of the time, though, we have to do this:

Point p = c.getSize();
c.setSize(p.x+1, p.y+1);
c.setSize(p);

我们已经在几乎所有布局管理器组合中实现了这一点。

We've had this happen with just about every combination of layout managers and such.

我希望我有一个漂亮,简单,可重复的案例,但我没有。我希望有人会认出这个问题并说:好吧,呃,你错过了xyz ....

I wish I had a nice, simple, reproducible case, but I don't. I'm hoping that someone will recognize this problem and say: "Well, duh, you're missing xyz...."

推荐答案

在我看来,布局的缓存已过时,需要刷新

SWT支持缓存中的布局,通常会缓存控件的首选大小,或者他们喜欢缓存的任何大小:

Layouts in SWT support caches, and will usually cache preferred sizes of the Controls, or whatever they like to cache:

public abstract class Layout {
    protected abstract Point computeSize (Composite composite, int wHint, int hHint, boolean flushCache);
    protected boolean flushCache (Control control) {...}
    protected abstract void layout (Composite composite, boolean flushCache);
}

我对SWT编程(以前的Swing程序员)比较陌生,但遇到过布局未正确更新的类似情况。我通常能够使用其他布局方法解决它们,这也会导致布局刷新其缓存:

I'm relatively new to SWT programming (former Swing programmer), but encountered similar situations in which the layout wasn't properly updated. I was usually able to resolve them using the other layout methods that will also cause the layout to flush its cache:

layout(boolean changed)

layout(boolean changed, boolean allChildren)

希望有帮助......

Hope that helps...

这篇关于为什么SWT Composite有时需要调用resize()才能正确布局?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆