当前位置: 首页 > 面试题库 >

为文本框创建气球工具提示吗?

微生宝
2023-03-14
问题内容

如何在SWT中为文本框创建气球工具提示?


问题答案:

这是修改后的SWT代码段,显示了如何将气球工具提示添加到SWT Text实例

下次,请考虑更具体地询问,我现在不这样做,如果您要查找的是..

/*
 * Tooltip example snippet: create a balloon tooltip for a tray item
 *
 * For a list of all SWT example snippets see
 * http://www.eclipse.org/swt/snippets/
 * 
 * @since 3.2
 */
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.FocusEvent;
import org.eclipse.swt.events.FocusListener;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.ToolTip;

public class TextFieldTooltip {

    public static void main(String[] args) {
        Display display = new Display();
        Shell shell = new Shell(display);
        shell.setLayout(new RowLayout(SWT.VERTICAL));
        final ToolTip tip = new ToolTip(shell, SWT.BALLOON);
        tip.setMessage("Here is a message for the user. When the message is too long it wraps. I should say something cool but nothing comes to my mind.");

        Text tfTooltip = new Text(shell, SWT.BORDER);
        tfTooltip.setText("sample text field");
        tfTooltip.addFocusListener(new FocusListener() {

            @Override
            public void focusLost(FocusEvent e) {
                tip.setVisible(false);
            }

            @Override
            public void focusGained(FocusEvent e) {
                Text actionWidget = (Text) e.widget;
                Point loc = actionWidget.toDisplay(actionWidget.getLocation());
                tip.setLocation(loc.x + actionWidget.getSize().x - actionWidget.getBorderWidth(), loc.y);
                tip.setVisible(true);
            }
        });
        Text tfNext = new Text(shell, SWT.BORDER);
        tfNext.setText("TF without tooltip");
        shell.setBounds(50, 50, 300, 200);
        shell.open();
        while (!shell.isDisposed()) {
            if (!display.readAndDispatch())
                display.sleep();
        }
        display.dispose();
    }
}


 类似资料:
  • 问题内容: 我想为工具提示创建一个自定义CSS类,该类将包裹长度超过25-30的字符串。通常这样长的文本不适合tootltip文本区域。 而且是否有使用[工具提示ui.bootstrap.tooltip)进行此操作?就像使用自定义CSS类来获取所需的输出。 这是简单的CSS工具提示 这是相同的代码片段: 问题答案: CSS解决方案 对于眼前的问题有一个非常简单的解决方案。我基本上添加的是以下CSS

  • 问题内容: 我正在尝试创建一个“气泡”,该气泡可以在事件触发时弹出,并且只要鼠标悬停在引发事件的项目上方,或者如果鼠标移入气泡中,它就会保持打开状态。我的泡沫将需要具有各种HTML和样式,包括超链接,图像等。 我基本上通过编写约200行丑陋的JavaScript来实现了这一目标,但是我真的很想找到一个jQuery插件或其他一些方法来解决这一问题。 问题答案: Qtip是我见过的最好的Qtip。它是

  • 我在eclipse rcp应用程序中使用jface tableviewer来显示一些值。 因此我写了以下片段... 这里是ConfigLabelProvider定义 现在我的问题是,如果列太小,默认的工具提示将试图显示完整的单元格文本值。 但是我得到了一个工具提示框,它对整个文本足够大,但是文本没有显示在单元格矩形之外。 如果我从CellLabelProvider扩展ConfigLabelProv

  • 可自定义的、可主题化的工具提示框,替代原生的工具提示框。 如需了解更多有关 tooltip 部件的细节,请查看 API 文档 工具提示框部件(Tooltip Widget)。 默认功能 悬停在链接上,或者使用 tab 键循环切换聚焦在每个元素上。 <!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>j

  • 我想在我的模型中使用“reason”属性为添加一个工具提示。我该怎么做?

  • 我真的很喜欢这个CSS工具提示的解决方案,我自己也用过一段时间了。但是我遇到了一个我以前从未遇到过的问题,多个工具提示的内容相互重叠,我不确定如何最好地解决它。 提到的解决方案基于管理绝对定位工具提示内容的