Java Utililty Methods Swing Font Width

List of utility methods to do Swing Font Width

Description

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

Method

intestimateWidth(Font font, String msg)
Estimates the width of the message being printed using the given font.
return FONT_LABEL.getFontMetrics(font).stringWidth(msg);
JEditorPanegetEditor(String html, int width, Color transparentColor, Font font)
Make a editor pane from the html
return getEditor(null, html, width, transparentColor, font);
StringgetHTMLTextForWidth(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)
...
intgetStringWidth(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);
intgetStringWidth(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);
intgetTextWidth(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;
intgetTextWidth(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());
booleanisFixedWidthFont(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);
...