JBLabel setAllowAutoWrapping usage

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);
4 comments
Comment actions Permalink

@... : any help is appreciated

0
Avatar
Permanently deleted user
Comment actions Permalink

Please try

JBLabel label = new JBLabel( "Location : " + Repository.dirLocation );
label.setCopyable(true);
label.setAllowAutoWrapping(true);

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()

2
Comment actions Permalink

Thank you. I will give it a try and update here.

0
Comment actions Permalink

It was helpful. Thank you.

0

Please sign in to leave a comment.