gpt4 book ai didi

java - 是否需要在 SWT 复合构造函数中调用 pack()/layout() ?

转载 作者:太空宇宙 更新时间:2023-11-04 07:36:59 24 4
gpt4 key购买 nike

我需要在小部件的构造函数中调用 pack() 和/或 layout() 吗?

(我按照 Wrapping an SWT Widget 上的说明进行操作)

public class MyWidget extends Composite
{
public MyWidget(Composite parent, int style)
{
super(parent, style);

setLayout(new GridLayout(1, false));

Label lblFoo = new Label(this, SWT.NONE);
lblFoo.setText("Don't panic");

Button btnNewButton = new Button(this, SWT.NONE);
btnNewButton.setText("OK");

pack(); // ?
layout(); // ?
}
}

最佳答案

简短的回答 - 不。您不必在构造函数中执行此操作。

正如 Marko Topolnik 在评论中提到的,这些方法将在小部件即将显示时执行。

关于java - 是否需要在 SWT 复合构造函数中调用 pack()/layout() ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16710013/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com