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

intgetCharsWidth(Font font, char[] chars, int offset, int length)
Gets the width of the specified char array.
if (chars == null) {
    return 0;
FontMetrics metrics = HELPER_LABEL.getFontMetrics(font);
return metrics.charsWidth(chars, offset, length);
FontgetFont(AttributeSet a)
get Font
StringBuffer buffer = new StringBuffer(StyleConstants.getFontFamily(a));
buffer.append('-');
if (StyleConstants.isBold(a)) {
    if (StyleConstants.isItalic(a)) {
        buffer.append("BOLDITALIC");
    } else {
        buffer.append("BOLD");
} else if (StyleConstants.isItalic(a)) {
    buffer.append("ITALIC");
} else {
    buffer.append("PLAIN");
buffer.append('-').append(StyleConstants.getFontSize(a));
Font f = Font.decode(buffer.toString());
return f;
voidincreaseLabelFont(JLabel label, int offset)
Modifica fontul de la un label si il face mai mare
Font oldFont = label.getFont();
label.setFont(oldFont.deriveFont(oldFont.getStyle(), oldFont.getSize() + offset));
voidinitGlobalFontSetting()
init Global Font Setting
Font font = new Font("SansSerif", Font.TRUETYPE_FONT, 12);
FontUIResource fontRes = new javax.swing.plaf.FontUIResource(font);
Enumeration<Object> keys = UIManager.getDefaults().keys();
while (keys.hasMoreElements()) {
    Object key = keys.nextElement();
    Object value = UIManager.get(key);
    if (value instanceof javax.swing.plaf.FontUIResource)
        UIManager.put(key, fontRes);
...
voidsetAntiAlisingFont()
set Anti Alising Font
System.setProperty("awt.useSystemAAFontSettings", "lcd");
System.setProperty("swing.aatext", "true");
voidsetBorderFromFont(JComponent c)
set Border From Font
FontMetrics metrics = c.getFontMetrics(c.getFont());
int top = metrics.getDescent();
int left = metrics.charWidth(' ');
c.setBorder(BorderFactory.createEmptyBorder(top, left, top, left));
voidsetComponentsFont(Container container, Font font)
set Components Font
Component[] components = container.getComponents();
container.setFont(font);
for (Component component : components) {
    component.setFont(font);
    if (component instanceof JMenu) {
        setComponentsFont((Container) component, font);
voidsetDefaultFont(final Font font)
set Default Font
UIDefaults uiDefaults = UIManager.getDefaults();
uiDefaults.put("TabbedPane.font", font);
uiDefaults.put("Button.font", font);
uiDefaults.put("List.font", font);
uiDefaults.put("PasswordField.font", font);
uiDefaults.put("TableHeader.font", font);
uiDefaults.put("Table.font", font);
uiDefaults.put("ToggleButton.font", font);
...
voidsetDefaultFont(Font font)
set Default Font
FontUIResource fontUIResource = new FontUIResource(font);
for (java.util.Map.Entry<?, ?> entry : UIManager.getDefaults().entrySet()) {
    if (entry.getKey().toString().toLowerCase().endsWith("font")) {
        UIManager.put(entry.getKey(), fontUIResource);
voidsetDefaultFont(java.awt.Font font)
set Default Font
setDefaultFontResource(new javax.swing.plaf.FontUIResource(font));