我正在开发eclipse JFace图形用户界面的东西。
我正在读取来自用户的一些输入,并能够使用验证器进行验证,如下所示。
// 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会发生什么(如图所示)。

任何帮助/想法都将不胜感激。
发布于 2019-12-17 16:18:19
您必须创建一个扩展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字段。
https://stackoverflow.com/questions/59369172
复制相似问题