gpt4 book ai didi

java - 向 InputDialog 添加注释

转载 作者:行者123 更新时间:2023-12-02 01:11:11 25 4
gpt4 key购买 nike

我正在研究 eclipse JFace GUI 的东西。

我正在读取用户的一些输入,并能够使用 validator 进行验证,如下所示。

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

我想要实现的是向用户添加与验证无关的注释。

基本上,该注释是关于描述按下“确定”按钮后会发生什么情况(如图所示)。

enter image description here

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

最佳答案

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

关于java - 向 InputDialog 添加注释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59369172/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com