You wonder why there may be a need to have a tooltip inside a JComboBox. What if your item is very long like the image shown below?

This where tooltips come in handy unless you plan to have your JComboBox display items in multi-line if they are very long but that won’t look good. A tooltip is the best solution and the way to go about this is to assign a renderer to the JComboBox that does this.

This class does the trick. You only need to instantiate this and assign it to the JComboBox by calling the setRenderer() method.

To create a multi-line JLabel, Samuel Sjoberg provided a custom class that extended the BasicLabelUI class in order to paint text and wrap them to multiple lines rather than displaying the text as one line and truncated with a …

To use the class, just do

Here is the full MultiLineLabelUI class.

Related Posts Plugin for WordPress, Blogger...