Java Utililty Methods Swing Font Set

List of utility methods to do Swing Font Set

Description

The list of methods to do Swing Font Set are organized into topic(s).

Method

voidsetMonospacedFont(JComponent component)
set Monospaced Font
if (MONOSPACED_FONT != null)
    component.setFont(MONOSPACED_FONT);
voidsetSwingFont(Font font)
set Swing Font
UIManager.put("Button.font", font);
UIManager.put("ToggleButton.font", font);
UIManager.put("RadioButton.font", font);
UIManager.put("CheckBox.font", font);
UIManager.put("ColorChooser.font", font);
UIManager.put("ToggleButton.font", font);
UIManager.put("ComboBox.font", font);
UIManager.put("ComboBoxItem.font", font);
...
JLabelsetTitleLabelFont(JLabel label)
set Title Label Font
return modifyLabelFont(label, Font.BOLD, 0);
voidsetUIDefaultFont()
set UI Default Font
Font defaultFont = null;
GraphicsEnvironment e = GraphicsEnvironment.getLocalGraphicsEnvironment();
Font[] fonts = e.getAllFonts(); 
for (Font f : fonts) {
    if ("verdana".equals(f.getFontName().toLowerCase())) {
        defaultFont = f;
        break;
if (defaultFont == null) {
    return;
Enumeration<Object> keys = UIManager.getDefaults().keys();
while (keys.hasMoreElements()) {
    Object key = keys.nextElement();
    Object value = UIManager.get(key);
    if (value != null && value instanceof FontUIResource) {
        FontUIResource oldFUR = (FontUIResource) value;
        UIManager.put(key,
                new FontUIResource(defaultFont.getFontName(), oldFUR.getStyle(), oldFUR.getSize()));
voidsetUIFont(final Font font)
Sets the font of all components in the current look and feel to the specified font, using the style and size from the original font.
for (Object key : UIManager.getDefaults().keySet()) {
    final Object value = UIManager.get(key);
    if (value instanceof FontUIResource) {
        final FontUIResource orig = (FontUIResource) value;
        UIManager.put(key, new UIDefaults.ProxyLazyValue("javax.swing.plaf.FontUIResource",
                new Object[] { font.getFontName(), orig.getStyle(), orig.getSize() }));
voidsetUIFont(final Font font)
Change the default font for all components.
FontUIResource uiFont = new FontUIResource(font);
UIManager.put("Label.font", uiFont);
UIManager.put("TabbedPane.font", uiFont);
UIManager.put("TextField.font", uiFont);
UIManager.put("PasswordField.font", uiFont);
UIManager.put("Button.font", uiFont);
UIManager.put("RadioButton.font", uiFont);
UIManager.put("CheckBox.font", uiFont);
...
voidsetUIFont(Font f)
Tries to set the font to the whole swing interface.
java.util.Enumeration keys = UIManager.getDefaults().keys();
FontUIResource fontResource = new FontUIResource(f);
while (keys.hasMoreElements()) {
    Object key = keys.nextElement();
    Object value = UIManager.get(key);
    if (value != null && value instanceof FontUIResource)
        UIManager.put(key, fontResource);
UIManager.put("defaultFont", fontResource);
voidsetUIFont(Font fon)
Sets the default Font for the current UIManager
FontUIResource f = new FontUIResource(fon);
Enumeration keys = UIManager.getDefaults().keys();
while (keys.hasMoreElements()) {
    Object key = keys.nextElement();
    Object value = UIManager.get(key);
    if (value != null && value instanceof javax.swing.plaf.FontUIResource) {
        UIManager.put(key, f);
for (Window w : Window.getWindows()) {
    SwingUtilities.updateComponentTreeUI(w);
voidsetUIFont(FontUIResource f)
set UI Font
Enumeration<Object> keys = UIManager.getDefaults().keys();
while (keys.hasMoreElements()) {
    Object key = keys.nextElement();
    Object value = UIManager.get(key);
    if (value != null && value instanceof FontUIResource)
        UIManager.put(key, f);
voidsetUIFont(FontUIResource f)
set UI Font
Enumeration keys = UIManager.getDefaults().keys();
while (keys.hasMoreElements()) {
    Object key = keys.nextElement();
    Object value = UIManager.get(key);
    if (value instanceof FontUIResource) {
        FontUIResource orig = (FontUIResource) value;
        Font font = new Font(f.getFontName(), orig.getStyle(), f.getSize());
        UIManager.put(key, new FontUIResource(font));
...