我有以下问题:
我正在SWT
为我的应用程序创建一个 GUI。我有一个TabFolder
,我在其中添加了几个TabItems
,并且在每一个中我创建了一个ScrolledComposite
包含一些内容的内容。
显示TabFolder
正常,但是ScrolledComposite
inTabFolder
仅在第一个中显示它的内容TabItem
。所有其他ScrolledComposites
人自己都可以看到,但它们的内容是不可见的。
这是一个小代码片段,演示了我所指的内容:
Display display = new Display();
Shell topShell = new Shell(display);
topShell.setSize(800, 800);
topShell.setBackground(display.getSystemColor(SWT.COLOR_YELLOW));
topShell.setLayout(new FillLayout());
TabFolder folder = new TabFolder(topShell, SWT.NONE);
for (int i = 0; i < 5; i++) {
TabItem item = new TabItem(folder, SWT.NONE);
item.setText("Item " + i);
ScrolledComposite scroller = new ScrolledComposite(folder,
SWT.H_SCROLL | SWT.V_SCROLL );
scroller.setBackground(display.getSystemColor(SWT.COLOR_BLUE));
Composite content = new Composite(scroller, SWT.NONE);
content.setBackground(display.getSystemColor(SWT.COLOR_RED));
scroller.setContent(content);
scroller.setExpandHorizontal(true);
scroller.setExpandVertical(true);
item.setControl(scroller);
}
topShell.setVisible(true);
while (!topShell.isDisposed()) {
display.readAndDispatch();
}
如果该区域被涂成红色,您可以判断内容正在显示。如果内容不可见,则该区域为蓝色(背景ScrolledComposite
)
我不确定这是否重要,但这发生在 Linux Mint 18 上,而且它似乎只发生在 GTK 3 中(在 2 中它工作得很好)
很长一段时间后,我将问题归结为以下问题:
事实证明,问题在于“缺失”内容的大小为零,因为布局没有设置这些内容的大小。
SWT.V_SCROLL
在我的情况下,可以通过SWT.H_SCROLL
从ScrolledComposite
. 因此,上面编写的代码按预期工作。
Display display = new Display();
Shell topShell = new Shell(display);
topShell.setSize(800, 800);
topShell.setBackground(display.getSystemColor(SWT.COLOR_YELLOW));
topShell.setLayout(new FillLayout());
TabFolder folder = new TabFolder(topShell, SWT.NONE);
for (int i = 0; i < 5; i++) {
TabItem item = new TabItem(folder, SWT.NONE);
item.setText("Item " + i);
ScrolledComposite scroller = new ScrolledComposite(folder,
SWT.NONE);
scroller.setBackground(display.getSystemColor(SWT.COLOR_BLUE));
Composite content = new Composite(scroller, SWT.NONE);
content.setBackground(display.getSystemColor(SWT.COLOR_RED));
scroller.setContent(content);
scroller.setExpandHorizontal(true);
scroller.setExpandVertical(true);
item.setControl(scroller);
}
topShell.setVisible(true);
while (!topShell.isDisposed()) {
display.readAndDispatch();
}
尽管这会导致所有内容的大小都被正确调整,但它会完全删除那些ScrollBars
在ScrolledComposite
某种程度上不是你想要的ScrolledComposite
.
有谁知道如何修复它或者这是否是一个错误(可能已在较新的 SWT 版本中修复)?