List of utility methods to do Swing Font
JLabel | addLabel(Container component, String text, Icon icon, int horizontalAlignment, Font font) Add a new label to a given component JLabel label = new JLabel(text, icon, horizontalAlignment); if (component != null) { component.add(label); if (font != null) { label.setFont(font); return label; ... |
void | applyComponentFont(JComponent c) apply Component Font c.setFont(guifont); |
void | applyFont(JPanel p) apply Font Component[] comps = p.getComponents();
for (Component c : comps) {
c.setFont(guifont);
|
void | applyProperties(final Component comp, final Color colBack, final Color colFore, final Font font) Sets background and foreground color and a font for the specified component. if (comp != null) {
comp.setBackground(colBack);
comp.setForeground(colFore);
comp.setFont(font);
|
void | autoAwesomeLookAndFeel(String fontName, Map auto Awesome Look And Feel if (!isWindows()) { setSystemLookAndFeel(); if (UIManager.getLookAndFeel().toString().contains("MetalLookAndFeel")) { FontUIResource font = new FontUIResource(fontName == null ? Font.SANS_SERIF : fontName.trim(), Font.PLAIN, 12); java.util.Enumeration keys = UIManager.getDefaults().keys(); while (keys.hasMoreElements()) { ... |
JComponent | boldFont(JComponent component) Updates a font in a component to be bold. if (component == null) return null; component.setFont(component.getFont().deriveFont(Font.BOLD)); return component; |
String | clipText(JComponent c, Font fnt, String val, int xFrom, int xTo) Clip a text. FontMetrics fm; String str; int i, size, totWidth; fm = c.getFontMetrics(fnt != null ? fnt : c.getFont()); totWidth = xFrom; size = val.length(); for (i = 0; i < size; i++) { totWidth += fm.charWidth(val.charAt(i)); ... |
AttributeSet | createTextAttributes(Font baseFont, Color color, boolean bold, boolean italic) Creates text style attributes with the specified properties. SimpleAttributeSet attrs = new SimpleAttributeSet(); if (baseFont != null) { StyleConstants.setFontFamily(attrs, baseFont.getFamily()); StyleConstants.setFontSize(attrs, baseFont.getSize()); StyleConstants.setForeground(attrs, color); StyleConstants.setBold(attrs, bold); StyleConstants.setItalic(attrs, italic); ... |
TextLayout | createTextLayout(JComponent c, String s, Font f, FontRenderContext frc) create Text Layout Object shaper = (c == null ? null : c.getClientProperty(TextAttribute.NUMERIC_SHAPING)); if (shaper == null) { return new TextLayout(s, f, frc); } else { Map<TextAttribute, Object> a = new HashMap<TextAttribute, Object>(); a.put(TextAttribute.FONT, f); a.put(TextAttribute.NUMERIC_SHAPING, shaper); return new TextLayout(s, a, frc); ... |
Font | defaultFont() default Font return (Font) UIManager.get("MenuItem.font"); |