我遇到以下问题:
我正在使用SWT
为我的应用程序创建GUI。我有一个TabFolder
,其中我添加了几个TabItems
,并在每个创建一个ScrolledComposite
,其中包含一些内容。将TabFolder大小内容的ScrolledCompsite设置为零
的TabFolder
是显示正常,但是在TabFolder
的ScrolledComposite
也只能说明它在第一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它的工作原理只是精)
后相当长的一段时间,我跟踪这个问题到以下几点:
原来的问题是,“丢失”的内容有一个大小为零,因为布点不设置的大小那些。
在我的情况下,可以通过从ScrolledComposite
中删除SWT.V_SCROLL
和SWT.H_SCROLL
样式常数来修复它。因此,按以下方式编写的上述代码按预期工作。
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();
}
虽然这会导致所有的内容进行适当规模的IT完全消除ScrolledComposite
的ScrollBars
这在某种程度上是不是你从ScrolledComposite
想要的东西。
有谁知道如何解决这个问题,或者这是否是一个错误(可能已在更新的SWT版本中修复)?
'TabFolder'确实会影响'ScrolledComposite'的行为吗?在Windows上,删除'TabFolder'并将shell作为'ScrolledComposite.'的父项后,我看不出有什么区别。 –
我不完全确定...我唯一能说的是,我已经体验过在第一个TabItem上一切都按预期工作的行为,并且在所有其他项目上ScrolledComposite都采用正确的站点,但是在ScrolledComposite中的Composite有一个大小为零,直到调整整个窗口的大小... – Raven