简体   繁体   English

如何将超链接添加到 Java SWT Label

[英]How to add hyperlink to a Java SWT Label

I have a org.eclipse.swt.widgets.Label and I want to add a Hyperlink to a specific portion of the Label Text.我有一个org.eclipse.swt.widgets.Label ,我想将超链接添加到 Label 文本的特定部分。 For example to have something like: "Click HERE " and when I click on HERE then a specific window will open.例如有类似:“点击这里”,当我点击这里时,一个特定的 window 将打开。

If it doesn't work with the Label, then what else can I use to have a Hyperlink?如果它不能与 Label 一起使用,那么我还能用什么来获得超链接? Thank you!谢谢!

Label is just plain text. Label只是纯文本。

The Link class ( org.eclipse.swt.widgets.Link ) allows text and links. Link class ( org.eclipse.swt.widgets.Link ) 允许文本和链接。 The Javadoc for Link.setText says: Link.setText的 Javadoc 说:

The string can contain both regular text and hyperlinks.该字符串可以包含常规文本和超链接。 A hyperlink is delimited by an anchor tag, <a> and </a>.超链接由锚标记 <a> 和 </a> 分隔。 Within an anchor, a single HREF attribute is supported.在锚点内,支持单个 HREF 属性。 When a hyperlink is selected, the text field of the selection event contains either the text of the hyperlink or the value of its HREF, if one was specified.选择超链接时,选择事件的文本字段包含超链接的文本或其 HREF 的值(如果已指定)。 In the rare case of identical hyperlinks within the same string, the HREF attribute can be used to distinguish between them.在同一字符串中的相同超链接的极少数情况下,可以使用 HREF 属性来区分它们。 The string may include the mnemonic character and line delimiters.该字符串可能包含助记符和行分隔符。 The only delimiter the HREF attribute supports is the quotation mark ("). Text containing angle-bracket characters < or > may be escaped using \, however this operation is a hint and varies from platform to platform. HREF 属性支持的唯一分隔符是引号 (")。包含尖括号字符 < 或 > 的文本可以使用 \ 进行转义,但是此操作是一个提示,并且因平台而异。

You must listen to the selection event from this control and add code to open the link.您必须从该控件侦听选择事件并添加代码以打开链接。

In an Eclipse plug-in you can use the Eclipse Forms FormText and Hyperlink controls which also allow mixed text and links plus other formatting.在 Eclipse 插件中,您可以使用 Eclipse Forms FormTextHyperlink控件,它们还允许混合文本和链接以及其他格式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM