Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change just the font size in SWT

Tags:

fonts

swt

I need to use a larger font for one of the labels.

label.setFont( new Font(display,"Arial", 14, SWT.BOLD ) );

but obviously Arial is not always the default font. I want to change just the size and keep everything else at default values.

Can I do something like

label.setFontSize( 14 );

to avoid setting the other parameters? Or can I at least find out the name of the font that is actually being used as default?

like image 829
Tomas Andrle Avatar asked Sep 10 '25 16:09

Tomas Andrle


1 Answers

I believe you could do something like

FontData[] fD = label.getFont().getFontData();
fD[0].setHeight(16);
label.setFont( new Font(display,fD[0]));

As long as no more than one font is returned, that should work.

like image 152
Mark K Avatar answered Sep 13 '25 04:09

Mark K