In this section, you will learn creating color dialog box and font dialog in Java.
SWT allows to show Color Dialog and Font Dialog by providing the classes FontDialog and ColorDialog. The FontDialog class provides the font dialog and allow the user to select a font from the available fonts. The ColorDialog class provides the color dialog and allows the user to select the color from the set of available colors.
The method dialog.open() makes the font dialog and color dialog visible. The method setFontData() sets the fontData describing the font to be selected by default in the dialog. The method text.setFont() sets the selected font. The method setForeground() sets the foreground color. The method setRGB() sets the selected color.
Here is the code of ShowDialogExample.java
Output will be displayed as:
On clicking Font Dialog button, the font dialog is displayed:
On clicking Color Dialog button, the color dialog is displayed:
Liked it! Share this Tutorial