无法调整 SWT 组件的大小 (TextMergeViewer)
Unable to resize a SWT component (TextMergeViewer)
这是我的问题:我一直在使用 SWT 为 Eclise 插件构建一个小 GUI。在下图中,部分 1,2,2',3,3' 的行为完全符合我的要求,并且正确地适合 window.
但是,第 4 部分(即 TextMergeViewer)在其容器的一角保持较小的尺寸。
例如,以下代码显示了我如何定义第 2 部分和第 2 部分':
Composite viewersContainer;
viewersContainer = new Composite(shell, SWT.BORDER);
viewersContainer.setLayout(new GridLayout(2, false));
viewersContainer.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
data = new GridData(SWT.FILL, SWT.FILL, true, true);
data.heightHint = 400;
data.widthHint = 400;
oldFileViewer = new Browser(viewersContainer, SWT.BORDER);
oldFileViewer.setText("here is the old file viewer\t\t\t\t\t\t\t\t\t\n\n\n\n\n\n");
oldFileViewer.setLayoutData(data);
newFileViewer = new Browser(viewersContainer, SWT.BORDER);
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.setLayoutData(data);
我在创建第 4 部分时尝试保留该模型,代码如下:
Composite c = new Composite(shell, SWT.BORDER);
c.setLayout(new GridLayout(1, false));
GridData l = new GridData(SWT.FILL, SWT.FILL, false, false);
c.setLayoutData(l);
TextMergeViewerCreator tmvc = new TextMergeViewerCreator();
TextMergeViewer tmv = null;
tmv = (TextMergeViewer) tmvc.createViewer(c, new CompareConfiguration());
DiffNode d = null;
try {
d = (DiffNode) (new CompareInput().prepareInput(new IProgressMonitor() {
//Some overrided methods
}
}));
} catch (InvocationTargetException | InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
d.setDontExpand(false);
tmv.setInput(d);
我猜 DiffNode 不负责 TextMergeViewer 文件,但我找不到我的代码中的错误。
任何帮助,将不胜感激 !
感谢阅读。
您需要将 GridData
设置为 TextMergeViewer
的 Control
:
tmv.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
另外,请注意:不要重复使用 GridData
对象。每个小部件都应该有自己的 GridData
.
NOTE: Do not reuse GridData objects. Every control in a Composite that is managed by a GridLayout must have a unique GridData object.
这是我的问题:我一直在使用 SWT 为 Eclise 插件构建一个小 GUI。在下图中,部分 1,2,2',3,3' 的行为完全符合我的要求,并且正确地适合 window.
但是,第 4 部分(即 TextMergeViewer)在其容器的一角保持较小的尺寸。
例如,以下代码显示了我如何定义第 2 部分和第 2 部分':
Composite viewersContainer;
viewersContainer = new Composite(shell, SWT.BORDER);
viewersContainer.setLayout(new GridLayout(2, false));
viewersContainer.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
data = new GridData(SWT.FILL, SWT.FILL, true, true);
data.heightHint = 400;
data.widthHint = 400;
oldFileViewer = new Browser(viewersContainer, SWT.BORDER);
oldFileViewer.setText("here is the old file viewer\t\t\t\t\t\t\t\t\t\n\n\n\n\n\n");
oldFileViewer.setLayoutData(data);
newFileViewer = new Browser(viewersContainer, SWT.BORDER);
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.setLayoutData(data);
我在创建第 4 部分时尝试保留该模型,代码如下:
Composite c = new Composite(shell, SWT.BORDER);
c.setLayout(new GridLayout(1, false));
GridData l = new GridData(SWT.FILL, SWT.FILL, false, false);
c.setLayoutData(l);
TextMergeViewerCreator tmvc = new TextMergeViewerCreator();
TextMergeViewer tmv = null;
tmv = (TextMergeViewer) tmvc.createViewer(c, new CompareConfiguration());
DiffNode d = null;
try {
d = (DiffNode) (new CompareInput().prepareInput(new IProgressMonitor() {
//Some overrided methods
}
}));
} catch (InvocationTargetException | InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
d.setDontExpand(false);
tmv.setInput(d);
我猜 DiffNode 不负责 TextMergeViewer 文件,但我找不到我的代码中的错误。 任何帮助,将不胜感激 ! 感谢阅读。
您需要将 GridData
设置为 TextMergeViewer
的 Control
:
tmv.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
另外,请注意:不要重复使用 GridData
对象。每个小部件都应该有自己的 GridData
.
NOTE: Do not reuse GridData objects. Every control in a Composite that is managed by a GridLayout must have a unique GridData object.