Ada*_*old 6 java eclipse-plugin eclipse-rcp
到目前为止我尝试了什么:
在createPartControl中:
ScrolledComposite sc = new ScrolledComposite(parent, SWT.V_SCROLL | SWT.H_SCROLL);
sc.setLayoutData(new GridData(GridData.FILL_BOTH));
sc.setExpandVertical(true);
sc.setExpandHorizontal(true);
sc.setSize(ApplicationWorkbenchWindowAdvisor.WIDTH, ApplicationWorkbenchWindowAdvisor.HEIGHT);
final TabFolder tabFolder = new TabFolder(sc, SWT.TOP);
Run Code Online (Sandbox Code Playgroud)
但这不起作用.我的问题是,如果我调整程序窗口的大小,滚动条不会出现在我的视图中.有任何想法吗?
ScrolledComposite的Javadoc描述了使用它的两种方法,包括示例代码.总结一下:
ScrolledComposite控件/合成本身中包含的控件/合成的大小ScrolledComposite使用其内容的最小尺寸.目前,你们两个都没做.您正在设置大小ScrolledComposite,但除非您不使用布局管理器,否则这没有多大意义.在任何情况下,请参阅上面的链接以获取一些官方示例代码.
通常在Eclipse视图中,我希望我的控件获取所有可用空间,并且只显示滚动条,否则控件将缩小到可用大小以下.
其他答案完全有效,但我想添加一个createPartControl方法的完整示例(Eclipse e4).
@PostConstruct
public void createPartControl(Composite parent) {
ScrolledComposite sc = new ScrolledComposite(parent, SWT.H_SCROLL | SWT.V_SCROLL);
Composite composite = new Composite(sc, SWT.NONE);
sc.setContent(composite);
composite.setLayout(new GridLayout(2, false));
Label label = new Label(composite, SWT.NONE);
label.setText("Foo");
Text text = new Text(composite, SWT.BORDER | SWT.WRAP | SWT.V_SCROLL | SWT.MULTI);
GridDataFactory.fillDefaults().grab(true, true).hint(400, 400).applyTo(text);
sc.setExpandHorizontal(true);
sc.setExpandVertical(true);
sc.setMinSize(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
}
Run Code Online (Sandbox Code Playgroud)
注意.fillDefaults()暗示.align(SWT.FILL, SWT.FILL).
我通常使用这种模式,所以我创建了以下小帮助方法:
public static ScrolledComposite createScrollable(Composite parent, Consumer<Composite> scrollableContentCreator) {
ScrolledComposite sc = new ScrolledComposite(parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
Composite composite = new Composite(sc, SWT.NONE);
sc.setContent(composite);
scrollableContentCreator.accept(composite);
sc.setExpandHorizontal(true);
sc.setExpandVertical(true);
sc.setMinSize(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
return sc;
}
Run Code Online (Sandbox Code Playgroud)
感谢Java 8 lambdas,您现在可以以非常紧凑的方式实现新的可滚动复合:
createScrollable(container, composite -> {
composite.setLayout(new FillLayout());
// fill composite with controls
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6214 次 |
| 最近记录: |