JFontChooser provides a Java font chooser component.
Selected Font
Code Samples:
// create a font chooser
JFontChooser fontChooser = new JFontChooser();
int retValue = fontChooser.showDialog(null);
// get the selected font
if(retValue == JFontChooser.OK_OPTION) {
Font selected = fontChooser.getSelectedFont();
// do something...
}
Font Effects
Code Samples:
// create a font chooser
JFontChooser fontChooser = new JFontChooser();
// set the font effect
Object[] EFFECT_SET = { "underline", "strikethrough", "superscript", "subscript" };
fontChooser.setEffectSet(EFFECT_SET);
Font Color
Code Samples:
// create a font chooser
JFontChooser fontChooser = new JFontChooser();
int retValue = fontChooser.showDialog(null);
// get the font color
if(retValue == JFontChooser.OK_OPTION) {
Color color = fontChooser.getFontColor();
// do something...
}
Build-in Show Dialog
Code Samples:
// create a font chooser
JFontChooser fontChooser = new JFontChooser();
// show a dialog contains JFontChooser component
int retValue = fontChooser.showDialog(null);
if(retValue == JFontChooser.OK_OPTION) {
// do something...
}