我的 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);
关于java - 向 SWT GUI 添加帮助按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32431745/