Java Utililty Methods Swing Font Change

List of utility methods to do Swing Font Change

Description

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

Method

voidchangeDefaultFontSize(int fontSize)
Code from http://stackoverflow.com/questions/1236231/managing-swing-ui-default-font-sizes-without-quaqua
UIDefaults defaults = UIManager.getDefaults();
Enumeration<Object> keys = defaults.keys();
while (keys.hasMoreElements()) {
    Object key = keys.nextElement();
    if ((key instanceof String) && (((String) key).endsWith(".font"))) {
        FontUIResource font = (FontUIResource) UIManager.get(key);
        defaults.put(key, new FontUIResource(font.getFontName(), font.getStyle(), fontSize));
voidchangeFont(JComponent comp, double scaleFactor, int style)
Scale the original font of a component by a given factor and change the style
Font font = comp.getFont();
font = scale(font, scaleFactor);
comp.setFont(font.deriveFont(style));
voidChangeFont(JComponent comp, int wheel_rotation)
Change Font
int size_inc = 0;
if (wheel_rotation > 0)
    size_inc++;
else if (wheel_rotation < 0)
    size_inc--;
if (size_inc != 0) {
    Font f = new Font(comp.getFont().getName(), comp.getFont().getStyle(),
            comp.getFont().getSize() + size_inc);
...
voidchangeFontSize(final int size)
change Font Size
UIDefaults defaults = UIManager.getLookAndFeelDefaults();
    float baseSize = getBaseFontSize();
    growthPercentage = size / baseSize;
defaults.keySet().stream().filter(keyObj -> keyObj instanceof String).forEach(keyObj -> {
    String key = (String) keyObj;
    if (key.contains("font")) {
...
FontchangeFontSize(Font font, float factor)
change Font Size
int size = (int) Math.round(factor * font.getSize());
if (size < 6)
    size = Math.max(6, font.getSize());
return new Font(font.getName(), font.getStyle(), size);
FontchangeFontStyle(Font font, int style)
change Font Style
return new Font(font.getName(), style, font.getSize());
JComponentchangeFontToItalic(final JComponent component)
Changes the font of a component to ITALIC.
component.setFont(component.getFont().deriveFont(Font.ITALIC));
return component;
voidinstallFont(Component c, Font font)
install Font
Font f = c.getFont();
if ((f == null) || ((f instanceof UIResource)))
    c.setFont(font);
voidinstallFont(Component c, Font font)
install Font
Font f = c.getFont();
if (f == null || f instanceof UIResource) {
    c.setFont(font);