[英]How to make SWT button Text BOLD
I am creating a checkbox button with text in SWT.我正在用 SWT 中的文本创建一个复选框按钮。
org.eclipse.swt.widgets.Button button= new Button(composite, SWT.CHECK);
button.setText(Messages.AnswerDialog_answer);
button.setSelection(true);
In messages.properties, I have the value在messages.properties,我有价值
AnswerDialog_answer=Answer
How can i show the text(ie. Answer) of this button in BOLD?如何以粗体显示此按钮的文本(即答案)?
You can convert the currently assigned font for the button to be bold using something like:您可以使用以下方式将当前分配的按钮字体转换为粗体:
FontData [] data = button.getFont().getFontData();
for (FontData datum : data) {
datum.setStyle(SWT.BOLD);
}
Font boldFont = new Font(button.getDisplay(), data);
button.setFont(boldFont);
Note: You must call boldFont.dispose()
when you are done with the font (such as when the dialog closes).注意:您必须在使用完字体后调用
boldFont.dispose()
(例如当对话框关闭时)。
I'm not sure that all platforms support changing the button font.我不确定所有平台都支持更改按钮字体。 The above code works on macOS.
上面的代码适用于 macOS。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.