Java 我可以让EclipseSWTUI看起来像eclipse插件UI吗?

Java 我可以让EclipseSWTUI看起来像eclipse插件UI吗?,java,eclipse,eclipse-plugin,swt,Java,Eclipse,Eclipse Plugin,Swt,我正在向eclipse添加一些功能,就像在eclipse插件中一样 我有一项是复选框选择(见图) 还有一个项目有单选按钮(我找不到类似单选按钮的ListSelectionDialog) public void display(List<String> list){ Display.getDefault().asyncExec(new Runnable(){ public void run() { Display display = Di

我正在向eclipse添加一些功能,就像在eclipse插件中一样

我有一项是复选框选择(见图)

还有一个项目有单选按钮(我找不到类似单选按钮的
ListSelectionDialog

public void display(List<String> list){
    Display.getDefault().asyncExec(new Runnable(){
        public void run() {
            Display display = Display.getDefault();
            Shell shell = new Shell(display);
            shell.setLayout(new GridLayout());
            shell.setText("Create Object");
            Label label = new Label(shell, SWT.NULL);
            label.setText("Entry point: ");
            for (String item: list){
                Button btn  = new Button(shell, SWT.RADIO);
                btn.setText(item);                    
            }
            Composite composite = new Composite(shell, SWT.NULL);
            composite.setLayout(new RowLayout());

            Button createButton = new Button(composite, SWT.PUSH);
            createButton.setText("Create");
            Button cancelButton = new Button(composite, SWT.PUSH);
            cancelButton.setText("Cancel");
            shell.setSize(400, 200);
            shell.open ();
            while (!shell.isDisposed ()) {
                if (!display.readAndDispatch ()) display.sleep ();
            }
            shell.dispose ();
                }
        });
}
公共作废显示(列表){
Display.getDefault().asyncExec(新的Runnable()){
公开募捐{
Display=Display.getDefault();
外壳=新外壳(显示);
setLayout(新的GridLayout());
shell.setText(“创建对象”);
标签=新标签(shell,SWT.NULL);
label.setText(“入口点:”);
用于(字符串项:列表){
按钮btn=新按钮(外壳、SWT.收音机);
btn.setText(项目);
}
复合材料=新复合材料(shell,SWT.NULL);
setLayout(新的RowLayout());
按钮createButton=新按钮(组合,SWT.PUSH);
createButton.setText(“创建”);
按钮取消按钮=新按钮(组合,SWT.PUSH);
cancelButton.setText(“取消”);
外壳尺寸(400200);
shell.open();
而(!shell.isDisposed()){
如果(!display.readAndDispatch())display.sleep();
}
shell.dispose();
}
});
}
正如您所看到的,基于SWT的项目看起来不合适,并且与Eclipse的UI不一致。
有没有可能使它看起来像另一个?

使用JFace
对话框提供标准外观。类似于:

public class CreateDialog extends Dialog
{
  public CreateDialog(final Shell parentShell)
  {
    super(parentShell);
  }

  @Override
  protected void configureShell(final Shell newShell)
  {
    super.configureShell(newShell);

    newShell.setText("Create Object");
  }

  @Override
  protected void createButtonsForButtonBar(Composite parent)
  {
    createButton(parent, IDialogConstants.OK_ID, "Create", true);
    createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false);
 }

  @Override
  protected Control createDialogArea(Composite parent)
  {
    Composite body  = (Composite)super.createDialogArea(parent);

    String [] list = {"e", "e1"};

    Label label = new Label(body, SWT.NULL);
    label.setText("Entry point: ");

    for (String item: list) {
        Button btn = new Button(body, SWT.RADIO);
        btn.setText(item);
    }

    return body;
  }
}

所有Eclipse对话框都使用SWT,通常也使用JFace
Dialog
,它提供了更高级别的界面,但基本上仍然是SWT。我不清楚您关心的对话框的哪些部分。首先,左上角图标不同;其次,窗口的大小(我强制它为400200),但它并不理想(就像另一个自动检测到的大小)第三,创建和取消按钮看起来不同。此外,我假设我需要将自己的侦听器添加到选定的收音机和取消/创建BTN?使用JFace
对话框
,您可以使用相同的
getOKButton()
调用以更改“确定”按钮文本。嘿,greg,非常感谢您的回答,它看起来确实很棒。我有一些后续操作a)我可以在CreateDialog构造函数中传递列表吗,这样我就不会在createDialogArea中有硬编码列表了?b)为什么shell在构造函数中是最终的?c) 如果我想返回所选单选按钮,是否需要向该调用添加另一个方法来侦听OK_ID按钮?d) createButtonsForButtonBar/createDialogArea/configureShell自动调用的是谁?我没有看到对它们的任何调用,所以我有点困惑它是如何神奇地自动创建窗口的。是的,您可以将列表传递给构造函数。Shell是final的,因为它没有被更改,我将Eclipse设置为尽可能添加final,并且在这里发布之前忘记了编辑这个Shell。按下Override
OK
以处理OK按钮按下。其他方法都是对基本
对话框中的代码的重写,并在对话框
创建
/
打开
调用期间调用。最后一个后续操作,因为我正在自动创建带有for循环````for(字符串项:列表){Button btn=new Button(body,SWT.radio)的单选btn“``既然我需要找出选择了哪个电台,我应该把所有的基站存储在一个Button[]数组中,然后当按下OK时,遍历该列表并调用isSelected,还是在JFace中有更好、更正确的方法来做到这一点?没有更好的方法了。
public class CreateDialog extends Dialog
{
  public CreateDialog(final Shell parentShell)
  {
    super(parentShell);
  }

  @Override
  protected void configureShell(final Shell newShell)
  {
    super.configureShell(newShell);

    newShell.setText("Create Object");
  }

  @Override
  protected void createButtonsForButtonBar(Composite parent)
  {
    createButton(parent, IDialogConstants.OK_ID, "Create", true);
    createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false);
 }

  @Override
  protected Control createDialogArea(Composite parent)
  {
    Composite body  = (Composite)super.createDialogArea(parent);

    String [] list = {"e", "e1"};

    Label label = new Label(body, SWT.NULL);
    label.setText("Entry point: ");

    for (String item: list) {
        Button btn = new Button(body, SWT.RADIO);
        btn.setText(item);
    }

    return body;
  }
}