rednight

0x2B|~0x2B,That's not a question,Just do it.
posts - 32, comments - 14, trackbacks - 0, articles - 0

创建一个多行的tooltip

Posted on 2006-11-08 09:22 rednight 阅读(267) 评论(0)  编辑  收藏

使用 IlvToolTipManager 创建一个多行的 tooltip  

1) 首先需要注册 view (IlvManagerView)I
lvToolTipManager.registerView(view);  

2) 创建需要显示的信息的数组,即每行的信息为数组中的一个元素:
new String[] tooltipArray ;  

3) 创建 tooltip, 第一个参数是上面创建的数组,第二个参数是显示位置,必须是 SwingConstants.LEFT , RIGHT , or CENTER String tooltip = IlvToolTipManager.createMultiLineToolTipText(tooltipArray, SwingConstants.LEFT);  

4) 设置 tooltip
IlvGraphic.setToolTipText(tooltip);



public static String createMultiLineToolTipText(String as[], int i)
    {
        String s;
        switch(i)
        {
        case 2: // '\002'
            s = "left";
            break;

        case 4: // '\004'
            s = "right";
            break;

        case 0: // '\0'
            s = "center";
            break;

        case 1: // '\001'
        case 3: // '\003'
        default:
            throw new IllegalArgumentException("Alignment must be LEFT, RIGHT, or CENTER");
        }
        Font font = UIManager.getFont("ToolTip.font");
        StringBuffer stringbuffer = new StringBuffer("<p align=\"");
        stringbuffer.append(s);
        stringbuffer.append("\" style=\"font-family:");
        stringbuffer.append(font.getName());
        stringbuffer.append(";font-size:");
        stringbuffer.append(font.getSize());
        stringbuffer.append("pt\">");
        String s1 = stringbuffer.toString();
        StringBuffer stringbuffer1 = new StringBuffer("<html>");
        for(int j = 0; j < as.length; j++)
        {
            stringbuffer1.append(s1);
            stringbuffer1.append(as[j]);
            stringbuffer1.append("</p>");
        }

        stringbuffer1.append("</html>");
        return stringbuffer1.toString();
    }

 


只有注册用户登录后才能发表评论。


网站导航: