JToggleButton with underlined text

Well, the name says it.

In Netbeans, I can change the font of JToggleButton, but there are only options for bold and italic, but not for underlined text. I assume this is not strictly a font property, but I cannot figure out how to do this.

+3
source share
1 answer

You can use HTML to display many components in Swing (see How to use HTML in Swing Components ), so you can create a line with underlined text and call JToggleButton.setText(String)or JToggleButton(String). for instance

new JToggleButton("<html><u>" + textToUnderline + "</u></html>");

(This closing tag </html>is optional, although I always include it).

+7
source

All Articles