简体   繁体   English

Draw2d:如何获得工具提示以保持更长的时间

[英]Draw2d: How to get a tooltip to stay longer

I have a program that creates tooltips using Figure.setToolTip(). 我有一个使用Figure.setToolTip()创建工具提示的程序。 Everything works great except that the tooltip disappears after a few seconds. 一切工作正常,除了工具提示会在几秒钟后消失。 The tooltip can contain a lot of information and I would like the tooltip to stay longer (or even indefinitely, until the cursor exits the figure). 工具提示可能包含很多信息,我希望工具提示停留更长时间(甚至无限期,直到光标退出图形为止)。

I haven't found any methods or fields in the ToolTipHelper class that deal with this. 我尚未在ToolTipHelper类中找到任何处理此问题的方法或字段。 Is this even possible to do? 这有可能吗?

The only other work around I can think of is to simply display a figure with the tooltips inside upon mouseEnter() and hide it on mouseExited(). 我能想到的唯一其他解决方法是简单地在mouseEnter()上显示带有工具提示的图形,然后将其隐藏在mouseExited()上。 But I would much rather use the built in tooltip feature. 但是我宁愿使用内置的工具提示功能。

I ended up using PopUpHelper which is the super class of ToolTipHelper. 我最终使用了PopUpHelper,它是ToolTipHelper的超类。 I simply added a MouseMotionListener to the Figure and on mouseEntered(MouseEvent arg0) and mouseExited(MouseEvent arg0) called tooltipHelper.show() and tooltipHelper.hide(). 我只是在图中添加了一个MouseMotionListener,并在mouseEntered(MouseEvent arg0)和mouseExited(MouseEvent arg0)上添加了一个名为tooltipHelper.show()和tooltipHelper.hide()的鼠标。

By calling getLightweightSystem().setContents(IFigure) and setShellBounds(int,int,int,int) in PopUpHelper I could determine what to display and where to display the tip. 通过在PopUpHelper中调用getLightweightSystem()。setContents(IFigure)和setShellBounds(int,int,int,int),我可以确定显示什么以及在哪里显示提示。

The pros are the tip stays as long as my cursor is inside the figure. 优点是只要我的光标停留在图形内,笔尖就会停留。 The tooltip is also the same size regardless of the scale of the canvas (this was stopping me from simply adding a Figure to the canvas and calling setVisible() and setLocation()). 无论画布的大小如何,工具提示的大小都是相同的(这使我无法简单地在画布上添加Figure并调用setVisible()和setLocation())。

Cons are you have to do most of the work yourself (the work ToolTipHelper was meant to do). 缺点是您必须自己完成大部分工作(ToolTipHelper本来可以完成工作)。 This includes hiding the tooltip in some unusual instances (such as, in my case, switching tabs while the mouse is still on the Figure) and coding the tooltip location to not run off screen. 这包括在一些不常见的情况下隐藏工具提示(例如,在我的情况下,当鼠标仍在图上时切换选项卡),并对工具提示的位置进行编码以使其不离开屏幕。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM