List of utility methods to do Swing Font
Rectangle | drawCentredText(Graphics2D g, Font font, String text, int x, int y) Draws the text by creating a rectange centered around x, y g.setFont(font); FontMetrics fm = g.getFontMetrics(font); setPreferredAliasingMode(g); Rectangle ret = new Rectangle(x, y, 0, 0); if (text == null) { return ret; String[] alines = text.split("\\n"); ... |
Rectangle | drawString(Graphics g, Font font, String text, Rectangle rect, int align) draw String return drawString(g, font, text, rect.x, rect.y, rect.width, rect.height, align);
|
void | drawString(Graphics g, String text, int x, int y, Font font, Color color) draw String Graphics2D g2d = (Graphics2D) g; RenderingHints oldHints = null; Color oc = g2d.getColor(); Font of = g2d.getFont(); if (renderingHints != null) { oldHints = g2d.getRenderingHints(); g2d.addRenderingHints(renderingHints); if (font != null) { g2d.setFont(font); if (color != null) { g2d.setColor(color); g2d.drawString(text, x, y); if (oldHints != null) { g2d.addRenderingHints(oldHints); g2d.setFont(of); g2d.setColor(oc); |
Font | getAsNotUIResource(Font font) Returns a Font based on the param which is not of type UIResource. if (!(font instanceof UIResource)) return font; return font.deriveFont(font.getAttributes()); |
Font | getDefaultFont() get Default Font return new JLabel().getFont(); |
Font | getDefaultLabelBoldFont() get Default Label Bold Font return UIManager.getFont("Label.boldFont"); |
Font | getDefaultLabelFont() get Default Label Font Font ref = new JLabel().getFont(); return ref.deriveFont(Font.PLAIN, ref.getSize()); |
Font | getFont(String name) get Font return getFont(name, getSystemLAF());
|
Color | getFontColorToUse(boolean isSelected) get Font Color To Use Color fontColorToUse; if (isSelected) { fontColorToUse = Color.WHITE; } else { if (LOOK_AND_FEEL_NAME.contains("Dark") || LOOK_AND_FEEL_NAME.equalsIgnoreCase("Darcula")) { fontColorToUse = FONT_COLOR_DARK; } else { fontColorToUse = FONT_COLOR_NORMAL; ... |
JTextArea | getHelpTextArea(String help, Color background, Font font) get Help Text Area JTextArea helpText = new JTextArea(help); helpText.setLineWrap(true); helpText.setWrapStyleWord(true); helpText.setBackground(background); helpText.setFont(font); helpText.setEditable(false); return helpText; |