向 InputDialog 添加注释
Adding a note to InputDialog
我正在研究 eclipse JFace GUI 的东西。
我正在读取用户的一些输入并能够使用如下验证器进行验证。
// creating input prompt
InputDialog inputDialog = new InputDialog(parentShell, dialogTitle, dialogMessage, initialValue, validator);
// Validator
IInputValidator validator = new IInputValidator()
{
@Override
public String isValid(String newName)
{
if (newName.isBlank())
{
return "Warning: Input is empty";
}
return null;
}
};
我想实现的是给用户添加一个与验证无关的注释。
基本上,注释是关于描述如果按下按钮 OK 会发生什么(如图所示)。
任何 help/idea 将不胜感激。
您必须创建一个新对话框 class 扩展 InputDialog
来执行此重写 createDialog
以添加额外的控件。类似于:
public class InputDialogWithNote extends InputDialog
{
private Label noteLabel;
public InputDialogWithNote(final Shell parentShell, final String dialogTitle, final String dialogMessage, final String initialValue, final IInputValidator validator)
{
super(parentShell, dialogTitle, dialogMessage, initialValue, validator);
}
@Override
protected Control createDialogArea(final Composite parent)
{
Composite body = (Composite)super.createDialogArea(parent);
noteLabel = new Label(body, SWT.LEAD);
noteLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
return body;
}
}
您将不得不安排一些方法来设置 noteLabel
字段。
我正在研究 eclipse JFace GUI 的东西。
我正在读取用户的一些输入并能够使用如下验证器进行验证。
// creating input prompt
InputDialog inputDialog = new InputDialog(parentShell, dialogTitle, dialogMessage, initialValue, validator);
// Validator
IInputValidator validator = new IInputValidator()
{
@Override
public String isValid(String newName)
{
if (newName.isBlank())
{
return "Warning: Input is empty";
}
return null;
}
};
我想实现的是给用户添加一个与验证无关的注释。
基本上,注释是关于描述如果按下按钮 OK 会发生什么(如图所示)。
任何 help/idea 将不胜感激。
您必须创建一个新对话框 class 扩展 InputDialog
来执行此重写 createDialog
以添加额外的控件。类似于:
public class InputDialogWithNote extends InputDialog
{
private Label noteLabel;
public InputDialogWithNote(final Shell parentShell, final String dialogTitle, final String dialogMessage, final String initialValue, final IInputValidator validator)
{
super(parentShell, dialogTitle, dialogMessage, initialValue, validator);
}
@Override
protected Control createDialogArea(final Composite parent)
{
Composite body = (Composite)super.createDialogArea(parent);
noteLabel = new Label(body, SWT.LEAD);
noteLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
return body;
}
}
您将不得不安排一些方法来设置 noteLabel
字段。