dictpopupmanager.java

来自「用java 实现屏幕取词技术」· Java 代码 · 共 50 行

JAVA
50
字号
/* * DictPopupManager.java * * Created on 2007-7-4, 17:13:27 * * To change this template, choose Tools | Templates * and open the template in the editor. */package dyno.swing.beans;import java.awt.Component;import java.awt.Font;import java.awt.Point;import javax.swing.JToolTip;import javax.swing.Popup;import javax.swing.PopupFactory;/** * * @author William Chen */public class DictPopupManager {    static Popup popup;    static Text last;        public static void show(Text text, Component src) {        hide();        last=text;        JToolTip tooltip = new JToolTip();        tooltip.setTipText(last.getTranslation());        tooltip.setFont(new Font("Dialog", 0, 12));        Point p = src.getLocationOnScreen();        int x = p.x + text.getX() + last.getWidth();        int y = p.y + text.getY() + last.getHeight();        popup = PopupFactory.getSharedInstance().getPopup(src, tooltip, x, y);        last.setVisible(true);        popup.show();    }    public static void hide(){        if(popup!=null && last!=null){            popup.hide();            last.setVisible(false);            popup=null;            last=null;        }    }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?