Java 向SWT GUI添加帮助按钮

Java 向SWT GUI添加帮助按钮,java,eclipse,user-interface,eclipse-plugin,swt,Java,Eclipse,User Interface,Eclipse Plugin,Swt,我的Eclipse应用程序中有一个简单的swt GUI,如下所示: 它的实现非常简单: // creating the label Label label = new Label(composite, SWT.NONE); label.setText("Label"); // creating the input field Text text = new Text(composite, SWT.BORDER); gridData.horizontalAlignment = SWT.FILL;

我的Eclipse应用程序中有一个简单的swt GUI,如下所示:

它的实现非常简单:

// creating the label
Label label = new Label(composite, SWT.NONE);
label.setText("Label");
// creating the input field
Text text = new Text(composite, SWT.BORDER);
gridData.horizontalAlignment = SWT.FILL;
gridData.grabExcessHorizontalSpace = true;
text.setLayoutData(gridData);
我想在标签和输入元素之间添加一个按钮,这样用户就可以获得关于在字段中添加什么的额外帮助

它可以是一个帮助按钮,也可以只是一个图标,在鼠标悬停时显示信息


我如何实现这一点?我将感谢任何帮助

执行此操作的许多方法之一是使用信息字段装饰

比如:

Text text = new Text(composite, SWT.BORDER);

FieldDecorationRegistry decRegistry = FieldDecorationRegistry.getDefault();

FieldDecoration infoField = decRegistry.getFieldDecoration(FieldDecorationRegistry.DEC_INFORMATION);

ControlDecoration decoration = new ControlDecoration(text, SWT.TOP | SWT.LEFT);
decoration.setImage(infoField.getImage());

decoration.setDescriptionText("Info decoration text");

GridData gridData = new GridData(SWT.FILL, SWT.CENTER, true, false);

// Space for decoration image
gridData.horizontalIndent = decRegistry.getMaximumDecorationWidth();

text.setLayoutData(gridData);

实现这一点的许多方法之一是使用信息字段装饰

比如:

Text text = new Text(composite, SWT.BORDER);

FieldDecorationRegistry decRegistry = FieldDecorationRegistry.getDefault();

FieldDecoration infoField = decRegistry.getFieldDecoration(FieldDecorationRegistry.DEC_INFORMATION);

ControlDecoration decoration = new ControlDecoration(text, SWT.TOP | SWT.LEFT);
decoration.setImage(infoField.getImage());

decoration.setDescriptionText("Info decoration text");

GridData gridData = new GridData(SWT.FILL, SWT.CENTER, true, false);

// Space for decoration image
gridData.horizontalIndent = decRegistry.getMaximumDecorationWidth();

text.setLayoutData(gridData);

注意:看起来您正在尝试重用GridData对象-永远不要这样做,始终为每个控件创建一个新的GridData。注意:看起来您正在尝试重用GridData对象-永远不要这样做,始终为每个控件创建一个新的GridData。这正是我要找的!非常感谢你!这正是我要找的!非常感谢你!