[英]ScrolledComposite no scrollbar in JFace dialog
我目前正在嘗試擴展JFace
對話框以包含scrolledComposite
。 我的代碼當前如下所示:
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
public class MWE extends MessageDialog {
public static void main(String[] args) {
Dialog d = new MWE(new Display().getActiveShell());
d.open();
}
public MWE(Shell parentShell) {
super(parentShell, "MWE", null, "",
MessageDialog.ERROR, new String[] { "OK" }, 0);
}
@Override
public Control createDialogArea(Composite parent) {
ScrolledComposite sc = new ScrolledComposite(parent, SWT.V_SCROLL);
sc.setExpandHorizontal(true);
sc.setExpandVertical(true);
sc.setMinSize(300, 300);
Composite content = new Composite(sc, SWT.NONE);
sc.setContent(content);
content.setLayout(new GridLayout());
for (int i = 0; i < 100; i++) {
Label l = new Label(content, SWT.NONE);
l.setText("lorem ipsum");
}
return parent;
}
}
問題是,像這樣,窗口的大小僅跨整個屏幕高度,如果超過一定大小,則無法滾動。 如果內容超出尺寸,如何滾動?
在ScrolledComposite
的布局數據中設置heightHint
:
GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
data.heightHint = 500;
sc.setLayoutData(data);
使用計算出的內容大小作為最小大小:
sc.setMinSize(content.computeSize(SWT.DEFAULT, SWT.DEFAULT));
(在將所有內容添加到content
之后執行此操作)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.