开发者

How to use new line character within a ToolTip [duplicate]

This question already has answers here: Closed 11 years ago.

Possible Duplicate:

Multi-line tooltips in Java?

It is very strange. All I wish to do is make my tool tip multi-lined. I have added the "\n" character to the string I am passing at appropriate plac开发者_JAVA技巧es. In fact, I print out that same string, and it does have the line breaks. However, the tooltip does not. Here is what I do:

        @Override
        public void itemStateChanged(ItemEvent arg0) {
            if(arg0.getStateChange() == ItemEvent.SELECTED){
                String s = arg0.getItem().toString();
                for(InfoContainer i: mc.myInfo)
                    if(s.equals(i.getId())){
                        selector.setToolTipText(i.getInfo());
                        System.out.println(i.getInfo());
                        return;
                    }
            }
        }

However, the tooltip does NOT have the carriage returns, while the System printout DOES.


How about using: "<html>" + firstLine + "<br>" + secondLine + "</html>"


Use the HTML tag <br/>:

selector.setToolTipText("<html>" + i.getInfo() + "<br/>some text next line</html>" );
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜