java - 我可以使 eclipse SWT UI 看起来像 Eclipse 插件 UI 吗?

标签 java eclipse eclipse-plugin swt

我正在向 Eclipse 添加一些功能,如 Eclipse 插件

我有一个项目是复选框选择(参见图片)

    final ListSelectionDialog dialog = new ListSelectionDialog(window.getShell(), list,
            ArrayContentProvider.getInstance(), new LabelProvider(), "");
    dialog.setTitle("Create Events");
    dialog.setHelpAvailable(false);
    dialog.setMessage("Potential events in code:");
    dialog.create();
    dialog.getOkButton().setText("Create");
    dialog.open();

以及另一个包含单选按钮的项目(我找不到类似 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 ();
                }
        });
}

正如您所看到的,基于 SWT 的项目看起来不合适并且与 Eclipse 的 UI 不一致。 有可能让它看起来像另一个吗? enter image description here

最佳答案

使用 JFace Dialog 提供标准外观。像这样的东西:

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;
  }
}

关于java - 我可以使 eclipse SWT UI 看起来像 Eclipse 插件 UI 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38061591/

相关文章:

java - 如何将值列表加载到模式弹出窗口

java - 对于 JDK 1.6,我应该使用哪个版本的 jfreechart 和 jcommon jar 文件

java - 如何更改 eclipse RCP 应用程序中首选项页面的标题?

java - 如何限制eclipse编译器

java - java - 如何使用java keystore而不是证书和 key 文件在java中使用ssl实例化grpc服务器?

java - 在 Android 中将月份 +1 添加到日历月份中的日历问题

eclipse - 在 Eclipse 中创建 Mule 项目

java - 端口绑定(bind) "problem"与 Eclipse、Java 和 Windows

java - 使用 LIBGDX 设置 Admob 时出错

eclipse - Eclipse Java Builder 开始失败