Chris Bolton
Chris Bolton

Reputation: 2312

Button setText not showing '&'

I am using org.eclipse.swt.widgets.Button and the setText method.

I am doing,

myButton.setText("A & B");

However, the & symbol is not displayed.

I have tried,

myButton.setText("A \\& B");
myButton.setText("A '&' B");
myButton.setText("A \& B"); \\not allowed

and none of them work.

Upvotes: 2

Views: 155

Answers (1)

Akash Thakare
Akash Thakare

Reputation: 23002

It is clearly stated in #setText doc,

Mnemonics are indicated by an '&' that causes the next character to be the mnemonic. When the user presses a key sequence that matches the mnemonic, a selection event occurs. On most platforms, the mnemonic appears underlined but may be emphasized in a platform specific manner. The mnemonic indicator character '&' can be escaped by doubling it in the string, causing a single '&' to be displayed.

So it should be like this,

myButton.setText("A && B");

Upvotes: 7

Related Questions