Java Utililty Methods Swing Font Metrics

List of utility methods to do Swing Font Metrics

Description

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

Method

StringgetClippedText(String text, FontMetrics fm, int maxWidth)
get Clipped Text
if ((text == null) || (text.length() == 0)) {
    return "";
int width = SwingUtilities.computeStringWidth(fm, text);
if (width > maxWidth) {
    int totalWidth = SwingUtilities.computeStringWidth(fm, ELLIPSIS);
    for (int i = 0; i < text.length(); i++) {
        totalWidth += fm.charWidth(text.charAt(i));
...
FontMetricsgetDefaultLabelFontMetrics()
Returns default label font metrics.
if (label == null) {
    label = new JLabel();
return label.getFontMetrics(label.getFont());
FontMetricsgetFontMetrics(final JComponent c, final Graphics g)
Returns the FontMetrics for the current Font of the passed in Graphics.
return getFontMetrics(c, g, g.getFont());
FontMetricsgetFontMetrics(Font font)
Gets the font metrics for the specified font.
return DUMMY_PANEL.getFontMetrics(font);
FontMetricsgetFontMetrics(Font font)
Returns a suitabel screen font metrics for the font.
return new JLabel().getFontMetrics(font);
FontMetricsgetFontMetrics(Font font)
Returns the font metrics object for a given font.
return Toolkit.getDefaultToolkit().getFontMetrics(font);
FontMetricsgetFontMetrics(JComponent c, Graphics g)
Returns the FontMetrics for the current Font of the passed in Graphics.
return getFontMetrics(c, g, g.getFont());
FontMetricsgetFontMetrics(JComponent c, Graphics g)
Returns the FontMetrics for the current Font of the passed in Graphics.
return getFontMetrics(c, g, g.getFont());
FontMetricsgetFontMetrics(JComponent c, Graphics g)
Copied from JDK's SwingUtilities2.java

Returns the FontMetrics for the current Font of the passed in Graphics.

return getFontMetrics(c, g, g.getFont());
FontMetricsgetFontMetrics(JComponent c, Graphics g)
Returns the FontMetrics for the current Font of the passed in Graphics.
return getFontMetrics(c, g, g.getFont());