java - 向 SWT GUI 添加帮助按钮

标签 java eclipse user-interface eclipse-plugin swt

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

Ecllipse appication window

它的实现非常简单:

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

相关文章:

java - 在 java 应用程序中具有分层特性的组件?

java - 在 Java 中下载 Pubmed Abstracts

python - 我的 UI 布局中的奇怪间距

java - Windows Defender 阻止在 Java 中获取指针位置

java - Spring : how to get multiple datasource with GenericDao?

java - 将 int 作为 boolean 值返回

eclipse - 我在 eclipse 中看到的唯一错误是:could not find or load main class. It compiles or gives this, nothing else. How can i see errors on console again?

java - 如何在 Java 中捕获 "never thrown"异常

java - 在 Flex 中渲染具有动态列的数据网格

ios - 如何在 UINavigationBar 标题上设置字距调整(字符间距)-Swift 或 Objective-C