gpt4 book ai didi

java - 按钮 setText 未显示 '&'

转载 作者:行者123 更新时间:2023-12-02 04:37:00 25 4
gpt4 key购买 nike

我正在使用 org.eclipse.swt.widgets.Button 和 setText 方法。

我正在做,

myButton.setText("A & B");

但是,& 符号不会显示。

我已经尝试过了,

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

但它们都不起作用。

最佳答案

#setText中有明确说明文档,

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.

所以应该是这样的,

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

关于java - 按钮 setText 未显示 '&',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26216673/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com