Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/319.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何控制swt工具提示的大小?_Java_Swt - Fatal编程技术网

Java 如何控制swt工具提示的大小?

Java 如何控制swt工具提示的大小?,java,swt,Java,Swt,嗨,我正试图在我的控件上使用swt工具提示,但我看到它的大小更大,这在控件上看起来很奇怪,比如beI see调用settooltiptext会给出关于文本确切大小的工具提示。有没有办法实现同样的效果 示例代码: import org.eclipse.swt.SWT; import org.eclipse.swt.events.FocusEvent; import org.eclipse.swt.events.FocusListener; import org.eclipse.swt.graphi

嗨,我正试图在我的控件上使用swt工具提示,但我看到它的大小更大,这在控件上看起来很奇怪,比如beI see调用settooltiptext会给出关于文本确切大小的工具提示。有没有办法实现同样的效果

示例代码:

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("tooltip");

        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 withdeafult");
        tfNext.setToolTipText("Default tooltip");
        shell.setBounds(50, 50, 300, 200);
        shell.open();
        while (!shell.isDisposed()) {
            if (!display.readAndDispatch())
                display.sleep();
        }
        display.dispose();
    }
}


我更喜欢ballon类型的工具提示出现在小的弹出窗口w.r.t文本中,而不是那么大的文本中。关于这一点的任何线索都会很有帮助

工具提示
似乎不支持任何自定义-但它是开源的,因此您可以始终尝试创建它的修改版本
setToolTipText
也不支持任何自定义。Ohk,谢谢,如果可以修改大小,我只需要指针。在扩展类并编写自定义类之前,只继续文本