Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java SWT Link widget - How can I remove the hyperlink underline?

I knew that we can use:

setText("<a> href="url"> Link </a>");

to set up a link. But the output of this is underlined.

I want to have a link that is not underlined, so I tried

setText(<a> href="url" style="text-decoration: none" Link </a>);

But it still doesnt work. Any HELP?

like image 562
Morty Choi Avatar asked Dec 30 '25 13:12

Morty Choi


2 Answers

Well, you cannot remove the underline. It is drawn internally with the help of the TextLayout class and there is no way to influence the behavior. By the way the HTML code for the text widget is only used internally for parsing. There is actually no HTML support for the Link widget. This is why the style attribute doesn't work. You can however use the StyledText widget for more advanced text layout.

like image 107
Tobias Willig Avatar answered Jan 02 '26 02:01

Tobias Willig


Just to add to Tobias Willig's answer, if your are working with JFace and Forms then you can use org.eclipse.ui.forms.widgets.Hyperlink and its setUnderlined(). You can see a working example here: Custom Components

like image 21
Favonius Avatar answered Jan 02 '26 02:01

Favonius