How to use new line character within a ToolTip [duplicate]
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>" );
精彩评论