[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [platform-swt-dev] Label ampersand in text

The javadoc for Label.setText() says "...The mnemonic indicator character '&' can be escaped by doubling it in the string, causing a single '&' to be displayed. ...".
So your initial strings need to have the && in them. Or you can use replaceAll before setting the text. Or you can use the method you used, but it is less efficient.


From: "Nazarenus, Jens" <Jens.Nazarenus@xxxxxxxxxxx>
To: "platform-swt-dev@xxxxxxxxxxx" <platform-swt-dev@xxxxxxxxxxx>
Date: 22/03/2010 04:55 AM
Subject: [platform-swt-dev] Label ampersand in text
Sent by: platform-swt-dev-bounces@xxxxxxxxxxx

I am developing a SWT application using org.eclipse.swt.widgets.Label.

When I include an ampersand <&> with label.setText("my company GmbH & Co. KG"); the character is not shown correctly.
Mostly an underline <_> is shown instead of the ampersand. It seems that SWT interprets the ampersand as the mnemonic character for the label.

What I have done:
I wrote a method which is invoked after setting the text for the label control.

public static void fixMnemonic(Label l) {
                String text = l.getText();
                l.setText(text.replaceAll("&", "&&"));

It works. But I am not happy with this solution.
Is there another way to bypass this issue?

platform-swt-dev mailing list