【发布时间】:2016-09-23 08:39:04
【问题描述】:
几天前我发现了 SWT,并决定将我的插件界面从 Swing 切换到 SWT。我可以随意放置组件,但是当我调整窗口大小时,组件根本不会调整大小。此外,当我用一个大字符串填充一个小文本(文本区域)时,我找不到调整它大小的方法...... 以下代码是定义布局和组件的代码,我想有人会发现我的错误在哪里。
P.S:我在网上看到一些教程在声明 shell 之前声明了一个 Display 对象。当我这样做时,我遇到了 InvalidThreadAccess 异常。
Shell shell = new Shell();
GridLayout gridLayout = new GridLayout(2, false);
shell.setLayout(gridLayout);
tree = new Tree(shell, SWT.CHECK | SWT.BORDER);
Text tips = new Text(shell, SWT.READ_ONLY);
tips.setText("Pick the files and nodes to refactor : ");
oldFileViewer = new Text(shell, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
oldFileViewer.setText("here is the old file viewer\t\t\t\t\t\t\t\t\t\n\n\n\n\n\n");
oldFileViewer.setSize(400, 400);
newFileViewer = new Text(shell, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
newFileViewer.setText("and here is the new file viewer\t\t\t\t\t\t\t\t\t\n\n\n\n\n\n");
newFileViewer.setSize(400, 400);
Button ok = new Button(shell, SWT.PUSH);
感谢阅读。
【问题讨论】:
-
使用布局时切勿手动设置尺寸。请阅读:Understanding Layouts in SWT
-
另外,请查看this answer,了解如何将
GridLayout与GridData一起使用。
标签: java eclipse eclipse-plugin swt