Java Utililty Methods Swing Font Size

List of utility methods to do Swing Font Size

Description

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

Method

intprintDocumentMonospacedWordWrap(Graphics g, Document doc, int fontSize, int pageIndex, PageFormat pageFormat, int tabSize)
Prints a Document using a monospaced font, word wrapping on the characters ' ', '\t', '\n', ',', '.', and ';'.
g.setColor(Color.BLACK);
g.setFont(new Font("Monospaced", Font.PLAIN, fontSize));
tabSizeInSpaces = tabSize;
fm = g.getFontMetrics();
int fontWidth = fm.charWidth('w'); 
int fontHeight = fm.getHeight();
int MAX_CHARS_PER_LINE = (int) pageFormat.getImageableWidth() / fontWidth;
int MAX_LINES_PER_PAGE = (int) pageFormat.getImageableHeight() / fontHeight;
...
voidresetUIFont(String name, int style, int size)
UIFonts reset
for (Map.Entry<Object, Object> entry : UIManager.getDefaults().entrySet()) {
    Object key = entry.getKey();
    Object value = UIManager.get(key);
    if (value != null && value instanceof FontUIResource) {
        FontUIResource f = new FontUIResource(name, style, size);
        UIManager.put(key, f);
voidresetUIFontSize(int size)
reset ui font size
for (Map.Entry<Object, Object> entry : UIManager.getDefaults().entrySet()) {
    Object key = entry.getKey();
    Object value = UIManager.get(key);
    if (value != null && value instanceof FontUIResource) {
        FontUIResource fr = (FontUIResource) value;
        FontUIResource f = new FontUIResource(fr.getFamily(), fr.getStyle(), size);
        UIManager.put(key, f);
doubleScaleLabelFontsizeAndDimension(JLabel label, int fontSize)
Scale Label Fontsize And Dimension
Font fontLabel = label.getFont();
Font newFont = new Font(fontLabel.getName(), fontLabel.getStyle(), fontSize);
double scaleFactor = fontSize / fontLabel.getSize();
double scaleFactorWidth = getGraphicsFontWidthAvg(newFont) / getGraphicsFontWidthAvg(fontLabel);
label.setFont(newFont);
if (label.getSize().getWidth() > 0)
    label.setSize((int) (label.getSize().getWidth() * scaleFactorWidth), fontSize);
else
...
voidsetFontSize(JLabel label, int i)
set Font Size
Font f = label.getFont();
Font newFont = new Font(f.getFamily(), f.getStyle(), i);
label.setFont(newFont);
voidsetFontSizeForComponent(JComponent component, int newFontSize)
set Font Size For Component
Font original = component.getFont();
Font newFont = original.deriveFont(Float.valueOf(newFontSize));
component.setFont(newFont);
voidsetLookAndFeel(int fontSize)
set Look And Feel
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
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));
...
voidsetUIFontSize(float size)
set UI Font Size
java.util.Enumeration keys = UIManager.getDefaults().keys();
while (keys.hasMoreElements()) {
    Object key = keys.nextElement();
    Object value = UIManager.get(key);
    if (value instanceof javax.swing.plaf.FontUIResource) {
        Font font = UIManager.getFont(key);
        if (font != null) {
            UIManager.put(key, new javax.swing.plaf.FontUIResource(font.deriveFont(size)));
...
voidsetUIManagerFont(int fontSize)
set UI Manager Font
Object uiObject;
Font uiManagerFont;
UIDefaults uiDefaults;
uiObject = null;
uiObject = UIManager.get("Label.font");
if (uiObject != null && uiObject instanceof Font)
    uiManagerFont = (Font) uiObject;
else
...
voidsetUIManagerFont(int fontSize)
set UI Manager Font
Object uiObject;
Font uiManagerFont;
UIDefaults uiDefaults;
uiObject = UIManager.get("Label.font");
if (uiObject != null && uiObject instanceof Font)
    uiManagerFont = (Font) uiObject;
else
    return;
...