Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Styling a SWT label to be italic

Tags:

java

swt

How would I go about styling a SWT label created along the following lines so it is displayed italicised?

Label label = formToolkit.createLabel(composite, "My label name");
like image 428
Simon Lieschke Avatar asked Dec 02 '09 01:12

Simon Lieschke


2 Answers

A recent article (February 2014 from Jordi Böhme López) suggest another way to get the current font in order to modify it:

it’s like getting the blueprint of the default font, making some changes and building a new font with the modified blueprint:

Label label = new Label(parent, SWT.NONE);
FontDescriptor descriptor = FontDescriptor.createFrom(label.getFont());
// setStyle method returns a new font descriptor for the given style
descriptor = descriptor.setStyle(SWT.BOLD);
label.setFont(descriptor.createFont(label.getDisplay));
label.setText("Bold Label");
like image 174
VonC Avatar answered Nov 10 '22 10:11

VonC


It would be better to use FontRegistry class from JFaces, like this:

label.setFont(
    JFaceResources.getFontRegistry().getItalic(JFaceResources.DEFAULT_FONT)
);
like image 25
Esteve Avatar answered Nov 10 '22 10:11

Esteve