如何填充 ScrolledComposite? [英] How to fill a ScrolledComposite?
本文介绍了如何填充 ScrolledComposite?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个从 ScrolledComposite 扩展的类,在这个类中我创建了一个复合材料,用于填充父级 ScrolledComposite.但是每当我将标签添加到内部复合材料时,它只会包装到右上角.我希望我的内部 Composite 完全填满外部 ScrolledComposite.有没有办法做到这一点?
I have a class extending from ScrolledComposite, within this class I have created a Composite which is intended to fill the parent ScrolledComposite. But whenever I add labels to the inner composite it wraps to the upper right corner only. I want my inner Composite to completely fill the outer ScrolledComposite. Is there a way to do this?
public class Container extends ScrolledComposite {
final Composite comp;
Label nameLabel, sizeLabel, dateLabel;
ArrayList<Label> entrySize, date;
ArrayList<SimpleEntry> entry;
Color white;
Font font;
public Container(Composite parent, int style) {
super(parent, style);
white = new Color(getDisplay(), 255, 255, 255);
font = new Font(getDisplay(), "Arial", 16, SWT.BOLD);
setBackground(white);
setLayout(new GridLayout(1, false));
comp = new Composite(this, SWT.BORDER);
GridData compData = new GridData(SWT.FILL, SWT.FILL, true, true);
comp.setLayoutData(compData);
setContent(comp);
comp.setBackground(white);
comp.setLayout(new GridLayout(3, false));
nameLabel = new Label(comp, SWT.BOLD);
sizeLabel = new Label(comp, SWT.BOLD);
dateLabel = new Label(comp, SWT.BOLD);
GridData d1 = new GridData(SWT.CENTER, SWT.CENTER, true, false);
nameLabel.setLayoutData(d1);
GridData d2 = new GridData(SWT.CENTER, SWT.CENTER, true, false);
sizeLabel.setLayoutData(d2);
GridData d3 = new GridData(SWT.CENTER, SWT.CENTER, true, false);
dateLabel.setLayoutData(d3);
nameLabel.setBackground(white);
sizeLabel.setBackground(white);
dateLabel.setBackground(white);
nameLabel.setText("Name");
sizeLabel.setText("Size");
dateLabel.setText("Last Modified");
nameLabel.setFont(font);
sizeLabel.setFont(font);
dateLabel.setFont(font);
comp.setSize(comp.computeSize(SWT.DEFAULT, SWT.DEFAULT));
comp.layout();
addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
Container.this.widgetDisposed(e);
}
});
}
}
推荐答案
只需在构造函数的末尾添加这些行:
Just add these lines at the end of the constructor:
this.setMinSize(comp.computeSize(SWT.DEFAULT, SWT.DEFAULT));
this.setExpandHorizontal(true);
this.setExpandVertical(true);
<小时>
注意事项:
Notes:
- 记得
dispose()
你自己创建的所有资源(Color
、Font
、...) - 考虑使用
display.getSystemColor(SWT.COLOR_WHITE)
和display.getSystemFont()
来使用系统资源(不需要处理).
- Remember to
dispose()
all resources you create yourself (Color
,Font
, ...) - Consider using system resources (no need to dispose) by using
display.getSystemColor(SWT.COLOR_WHITE)
anddisplay.getSystemFont()
.
这篇关于如何填充 ScrolledComposite?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文