java SWT:最有效的layout方法Control.requestLayout()

24 篇文章 0 订阅

Eclipse SWT最新的版本中org.eclipse.swt.widgets.Control增加了一个新方法requestLayout()用于更高效的处理layout请求
该方法其实只有一行代码:

public void requestLayout () {
    getShell ().layout (new Control[] {this}, SWT.DEFER);
}

这是SWT当前最高效的触发layout的办法,但是目前大多数开发者还是习惯使用性能更差的 Composite.layout()方法,
下面是说明原文:

SWT has added a new requestLayout() method to the Control and Composite classes. This method does essentially the same thing as
widget.getShell().layout(new Control[] {widget}, SWT.DEFER);
The snippet, above, is currently the most efficient method of triggering layouts in SWT, but most developers are unaware of this. Most Eclipse developers invoke Composite.layout(), which is worse in the sense of performance. This new API is intended to make it easier for developers to adopt the more efficient mechanism as opposed to using Composite#layout().

However, be aware that changing existing invocations of layout() to requestLayout() may break code that assumes that controls are completely sized and positioned at a certain point in time.

参考

《Eclipse Project Neon (4.6) M4 - New and Noteworthy》
《http://www.vogella.com/tutorials/SWT/article.html》

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

10km

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值