List of utility methods to do Swing Font Change
void | changeDefaultFontSize(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)); |
void | changeFont(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)); |
void | ChangeFont(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); ... |
void | changeFontSize(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")) { ... |
Font | changeFontSize(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); |
Font | changeFontStyle(Font font, int style) change Font Style return new Font(font.getName(), style, font.getSize()); |
JComponent | changeFontToItalic(final JComponent component) Changes the font of a component to ITALIC. component.setFont(component.getFont().deriveFont(Font.ITALIC));
return component;
|
void | installFont(Component c, Font font) install Font Font f = c.getFont(); if ((f == null) || ((f instanceof UIResource))) c.setFont(font); |
void | installFont(Component c, Font font) install Font Font f = c.getFont(); if (f == null || f instanceof UIResource) { c.setFont(font); |