How to use the new line symbol in the tooltip

Possible duplicate:
Multi-line hints in Java?

It is very strange. All I want to do is make my tool a multi-liner tooltip. I added the character "\ n" to the string that I am passing in the appropriate places. In fact, I am printing the same line and it has line breaks. However, the tooltip does not work. That's what I'm doing:

@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 carriage DOES NOT return in the tooltip while the system printout is displayed.

+6
source share
2 answers

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

+10
source

Use the HTML tag <br/> :

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

Source: https://habr.com/ru/post/892711/


All Articles