Java 带有ScrolledComposite的Jface对话框
我试图在我的对话框窗口中显示可滚动的组合 但是它没有滚动条。我也没有“确定”“取消”按钮 如何修复它Java 带有ScrolledComposite的Jface对话框,java,eclipse,swt,jface,Java,Eclipse,Swt,Jface,我试图在我的对话框窗口中显示可滚动的组合 但是它没有滚动条。我也没有“确定”“取消”按钮 如何修复它 public class MyDialog extends Dialog { public MyDialog (Shell parentShell) { super(parentShell); } protected void configureShell(Shell newShell) { super.configureShell(newShell)
public class MyDialog extends Dialog {
public MyDialog (Shell parentShell) {
super(parentShell);
}
protected void configureShell(Shell newShell) {
super.configureShell(newShell);
newShell.setText("test");
newShell.setSize(200, 100);
}
protected Control createDialogArea(Composite parent) {
ScrolledComposite sc = new ScrolledComposite(parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
Composite composite = new Composite(sc, SWT.NONE);
composite.setLayout(new FillLayout(SWT.VERTICAL));
new Label(composite, SWT.NONE).setText("1111");
new Label(composite, SWT.NONE).setText("2222");
new Label(composite, SWT.NONE).setText("3333");
new Label(composite, SWT.NONE).setText("4444");
new Label(composite, SWT.NONE).setText("5555");
new Label(composite, SWT.NONE).setText("6666");
new Label(composite, SWT.NONE).setText("7777");
sc.setContent(composite);
sc.setExpandHorizontal(true);
sc.setExpandVertical(true);
return parent;
}
好的,我几乎让它工作了。但是,在底部,对话框按钮所在的位置有一些空白。如果这不影响您,或者您打算添加按钮,下面的代码将执行您想要的操作。如果没有,我不知道如何帮助你
public class MyDialog extends Dialog
{
protected MyDialog(Shell parentShell) {
super(parentShell);
}
protected void configureShell(Shell newShell) {
super.configureShell(newShell);
newShell.setText("test");
newShell.setSize(200, 100);
}
protected void createButtonsForButtonBar(Composite parent) {
}
protected Control createDialogArea(Composite parent) {
Composite content = (Composite) super.createDialogArea(parent);
content.setLayout(new FillLayout());
ScrolledComposite sc = new ScrolledComposite(content, SWT.H_SCROLL
| SWT.V_SCROLL | SWT.BORDER);
Composite composite = new Composite(sc, SWT.NONE);
composite.setLayout(new FillLayout(SWT.VERTICAL));
new Label(composite, SWT.NONE).setText("1111");
new Label(composite, SWT.NONE).setText("2222");
new Label(composite, SWT.NONE).setText("3333");
new Label(composite, SWT.NONE).setText("4444");
new Label(composite, SWT.NONE).setText("5555");
new Label(composite, SWT.NONE).setText("6666");
new Label(composite, SWT.NONE).setText("7777");
sc.setContent(composite);
sc.setExpandHorizontal(true);
sc.setExpandVertical(true);
sc.setMinSize(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
return parent;
}
}
但是,我假设您将使用对话框按钮。否则,您可以简单地使用一个具有复合结构的shell,如我之前发布的示例所示…好的,所以我几乎让它工作了。但是,在底部,对话框按钮所在的位置有一些空白。如果这不影响您,或者您打算添加按钮,下面的代码将执行您想要的操作。如果没有,我不知道如何帮助你
public class MyDialog extends Dialog
{
protected MyDialog(Shell parentShell) {
super(parentShell);
}
protected void configureShell(Shell newShell) {
super.configureShell(newShell);
newShell.setText("test");
newShell.setSize(200, 100);
}
protected void createButtonsForButtonBar(Composite parent) {
}
protected Control createDialogArea(Composite parent) {
Composite content = (Composite) super.createDialogArea(parent);
content.setLayout(new FillLayout());
ScrolledComposite sc = new ScrolledComposite(content, SWT.H_SCROLL
| SWT.V_SCROLL | SWT.BORDER);
Composite composite = new Composite(sc, SWT.NONE);
composite.setLayout(new FillLayout(SWT.VERTICAL));
new Label(composite, SWT.NONE).setText("1111");
new Label(composite, SWT.NONE).setText("2222");
new Label(composite, SWT.NONE).setText("3333");
new Label(composite, SWT.NONE).setText("4444");
new Label(composite, SWT.NONE).setText("5555");
new Label(composite, SWT.NONE).setText("6666");
new Label(composite, SWT.NONE).setText("7777");
sc.setContent(composite);
sc.setExpandHorizontal(true);
sc.setExpandVertical(true);
sc.setMinSize(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
return parent;
}
}
但是,我假设您将使用对话框按钮。否则,您可以简单地使用一个具有复合的shell,如我之前发布的示例所示…@user1658192另外删除这一行:
newShell.setSize(200100)
@user1658192尝试我提供的代码示例。这对你有用吗?我相信如果没有像你那样的对话,它会有用的。我需要它来工作dialog@user1658192我明白这一点。我正试图缩小你的问题范围。。。你试过了吗?这对我有用!唯一的变化是Composite content=(Composite)super.createDialogArea(parent)
为什么新组合(…)
不起作用?@user1658192另外删除这一行:newShell.setSize(200100)
@user1658192尝试我提供的代码示例。这对你有用吗?我相信如果没有像你那样的对话,它会有用的。我需要它来工作dialog@user1658192我明白这一点。我正试图缩小你的问题范围。。。你试过了吗?这对我有用!唯一的变化是Composite content=(Composite)super.createDialogArea(parent)代码>为什么新组合(…)
不起作用?