JBLabel setAllowAutoWrapping usage Follow
Answered
For plugin development, I am using JBLabel inside DialogWrapper to display the long directory path. For auto wrapping of the text, I set allow auto wrapping as below. Is its intended use?
Though I set it true, label is getting truncated and not getting wrapped. Any example would be more helpful
JBLabel label = new JBLabel( "Location : " + Repository.dirLocation );
label.setAllowAutoWrapping(true);
Please sign in to leave a comment.
@... : any help is appreciated
Please try
Autowrapping doesn't work by itself. You can use standard JLabel with text like <html><body>The first line<br>The second line</body></html> or use JTextArea where auto-wrapping is supported, see JTextArea.setLineWrap() and JTextArea.setWrapStyleWord().
Actally JBLabel.setCopyable(true) adds JEditorPane inside JBLabel and provides auto-wrapping ability (as well as make text selectable and copyable). Please note that long directory path without spaces may be not wrapped at all as it's just 'one very long word'.
Probably it would be more convenient and generic to trim long (e.g. hardy readable) paths and make them more user-friendly with com.intellij.openapi.util.text.StringUtil.trimMiddle()
Thank you. I will give it a try and update here.
It was helpful. Thank you.