List of utility methods to do Swing Font Width
int | estimateWidth(Font font, String msg) Estimates the width of the message being printed using the given font. return FONT_LABEL.getFontMetrics(font).stringWidth(msg);
|
JEditorPane | getEditor(String html, int width, Color transparentColor, Font font) Make a editor pane from the html return getEditor(null, html, width, transparentColor, font);
|
String | getHTMLTextForWidth(JComponent comp, double bboxWth, String txt, Font font) get HTML Text For Width boolean useJComp = false; Vector<String> multiLineText = null; int htmlTextIndex = txt.indexOf("<html>"); if (htmlTextIndex == -1) htmlTextIndex = txt.indexOf("<HTML>"); if (htmlTextIndex != -1) return txt; if (useJComp) ... |
int | getStringWidth(final Font aFont, final String aString) Returns the string width for a given Font and string. final FontMetrics frc = createFontMetrics(aFont); return SwingUtilities.computeStringWidth(frc, aString); |
int | getStringWidth(Font font, String str) Gets the width of the specified String. if (str == null) { return 0; FontMetrics metrics = HELPER_LABEL.getFontMetrics(font); return metrics.stringWidth(str); |
int | getTextWidth(final String text, final Font font) Gets the text width. AffineTransform affinetransform = new AffineTransform(); FontRenderContext frc = new FontRenderContext(affinetransform, true, true); int textwidth = (int) (font.getStringBounds(text, frc).getWidth()); int textheight = (int) (font.getStringBounds(text, frc).getHeight()); return textwidth; |
int | getTextWidth(Font font, String text) get Text Width JLabel label = new JLabel(text); label.setFont(font); FontMetrics metrics = label.getFontMetrics(label.getFont()); return metrics.stringWidth(label.getText()); |
boolean | isFixedWidthFont(String fontName, Component component) Checks if the font specified by the font name is fixed width font. if (fontName.endsWith(" Bold") || fontName.endsWith(" ITC") || fontName.endsWith(" MT") || fontName.endsWith(" LET") || fontName.endsWith(".bold") || fontName.endsWith(".italic")) return false; try { Font font = new Font(fontName, 0, 12); if (!font.canDisplay('W')) return false; Font boldFont = font.deriveFont(Font.BOLD); ... |