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");
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");
It would be better to use FontRegistry
class from JFaces
, like this:
label.setFont(
JFaceResources.getFontRegistry().getItalic(JFaceResources.DEFAULT_FONT)
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With