Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JPanel titled border with tooltip text for the title

I am using setBorder(BorderFactory.createTitledBorder(title)) in my JPanel in order to group its content in a rectangle with a title above it. How can I set a tooltip text for the title?

like image 903
Hamid Fadishei Avatar asked Sep 09 '13 06:09

Hamid Fadishei


1 Answers

A possible approach is nesting components. As Borders are not components they can not have tooltips, but you can have a component with the sole purpose of holding border and the tooltip:

JPanel outer = new JPanel();
outer.setBorder(BorderFactory.createTitledBorder("Title"));
outer.setToolTipText("sample text");
JPanel inner = new JPanel();
outer.add(inner);

and then use inner as the container for the components you want to group.

like image 160
kiheru Avatar answered Sep 21 '22 10:09

kiheru