栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

当前显示的动态更新工具提示

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

当前显示的动态更新工具提示

实际上,即使在两次调用之间将工具提示重置为null时,它也不会自我更新。

到目前为止,我发现的唯一技巧是模拟鼠标移动事件并将其转发到TooltipManager上。这使他认为鼠标已移动并且必须重新放置工具提示。不漂亮,但是效率很高。

看一下这个演示代码,它以百分比显示从0到100的进度:

import java.awt.MouseInfo;import java.awt.Point;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.MouseEvent;import javax.swing.Jframe;import javax.swing.JLabel;import javax.swing.SwingUtilities;import javax.swing.Timer;import javax.swing.ToolTipManager;public class TestTooltips {    protected static void initUI() {        Jframe frame = new Jframe("test");        final JLabel label = new JLabel("Label text");        frame.add(label);        frame.pack();        frame.setVisible(true);        Timer t = new Timer(1000, new ActionListener() { int progress = 0; @Override public void actionPerformed(ActionEvent e) {     if (progress > 100) {         progress = 0;     }     label.setToolTipText("Progress: " + progress + " %");     Point locationOnScreen = MouseInfo.getPointerInfo().getLocation();     Point locationOnComponent = new Point(locationOnScreen);     SwingUtilities.convertPointFromScreen(locationOnComponent, label);     if (label.contains(locationOnComponent)) {         ToolTipManager.sharedInstance().mouseMoved(      new MouseEvent(label, -1, System.currentTimeMillis(), 0, locationOnComponent.x, locationOnComponent.y,   locationOnScreen.x, locationOnScreen.y, 0, false, 0));     }     progress++; }        });        t.start();    }    public static void main(String[] args) {        SwingUtilities.invokeLater(new Runnable() { @Override public void run() {     initUI(); }        });    }}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/515034.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号