我正在向 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 不一致。 有可能让它看起来像另一个吗?
最佳答案
使用 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/