在Swing JTextArea上弹出文本鼠标悬停? [英] Text-mouseover popups over a Swing JTextArea?

查看:114
本文介绍了在Swing JTextArea上弹出文本鼠标悬停?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有任何内容允许您在单个单词或Swing JTextArea中的字母上显示一个小文本弹出窗口(如工具提示)? (或具有类似功能的JTextArea替代方案。)

Is there anything out there that allows you to show a small text popup window (like a tooltip) over individual words or letters in a Swing JTextArea? (Or a JTextArea alternative with similar functionality.)

我需要的应该像工具提示一样,换句话说,只有在鼠标悬停在单词上方后才会显示弹出文本一两秒钟,一旦鼠标离开,它会自动消失。当然,这里棘手的部分是我希望它在文本中的字符/单词级别,而不是在组件级别...任何建议?

What I need should behave like a tooltip, in other words only display the popup text after the mouse has hovered over the word for a second or two, and it would vanish automatically once the mouse moves away. Of course the tricky part here is that I want it at the character/word level within the text, not at the component level... any suggestions?

推荐答案

您可以覆盖 getToolTipText(鼠标事件事件) 根据需要。

You can override getToolTipText(Mouse Event event) as needed.

附录:< a href =http://download.oracle.com/javase/6/docs/api/javax/swing/text/JTextComponent.html> JTextComponent JTextArea 的父级通过两种方法提供位置信息: modelToView() viewToModel() 后者应该让您将鼠标位置转换为文档偏移量。

Addendum: JTextComponent, the parent of JTextArea provides location information via two methods: modelToView() and viewToModel(). The latter should let you translate the mouse location into a document offset.

这篇关于在Swing JTextArea上弹出文本鼠标悬停?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆