【问题标题】:Adding a note to InputDialog向 InputDialog 添加注释
【发布时间】:2019-12-17 16:18:18
【问题描述】:

我正在研究 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 按钮时会发生什么(如图所示)。

任何帮助/想法将不胜感激。

【问题讨论】:

  • 这个文本会改变还是固定?
  • 是固定文本

标签: java eclipse jface


【解决方案1】:

您必须创建一个扩展 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 字段。

【讨论】:

  • 我收到编译器错误。 "方法 setLayoutData(GridData) 未为 Label 类型定义"
  • 您导入了错误的标签 - 它必须是 org.eclipse.swt.widgets.Label
猜你喜欢
  • 2014-04-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多