This section illustrates you how to create a Styled Text.
To display the stylish and impressive text, we have used the class StyledText of package org.eclipse.swt.custom. The class StyleRange allows to create an array to hold the StyleRanges. We have create seven StyleRanges to display the text. The ranges[].underline is of Boolean type which underlines the styleRange. The ranges[].background sets the background color by using shell.getDisplay().getSystemColor(SWT.COLOR_YELLOW). The ranges[3].fontStyle = SWT.BOLD sets the font of the StyleRange.
The method styledText.setFont(font) sets the font of the StyledText by using the class Font. The method styledText.replaceStyleRanges(0, 48, ranges) replace the style in the given range.
Here is the code of StyledTextExample.java
import org.eclipse.swt.SWT;
|
Output will be displayed as:

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.
Ask Questions? Discuss: StyledText in SWT
Post your Comment