This section illustrates you the use of ColorRegistry and FontRegistry.
SWT provides a great application of ColorRegistry and FontRegistry. These are the classes of package org.eclipse.jface.resource. The class ColorRegistry owns all of the color objects registered with it, and automatically disposes of them by disposing the SWT Display that creates the colors. Similarly the class FontRegistry owns all of the font objects registered with it, and automatically disposes of them by disposing the SWT Display that creates the Font.
We have create a label which shows the changes. A button is created to perform an action by calling the SelectionEvent class.
Following code adds a color to the ColorRegistry and a font to the FontRegistry:
| colorRegistry.put(FOREGROUND, new RGB((int) (Math.random() * 255), (int) (Math.random() * 255), (int) (Math.random() * 255))); FontData data = new FontData("Arial Narrow",(int) (Math.random() * 62), SWT.BOLD); fontRegistry.put(FONT, new FontData[] { data}); |
Then we create the method propertyChange() to set the property into label. The method colorRegistry.get(FOREGROUND) returns the color associated with the given symbolic color name and the method fontRegistry.get(FONT) returns the font associated with the given symbolic font name.
Here is the code of ShowRegistryExample.java
import org.eclipse.jface.resource.*;
|
Output will be displayed as:

On clicking the button, 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: Use of ColorRegistry and FontRegistry
Post your Comment