Class RenderingUtils


  • public final class RenderingUtils
    extends java.lang.Object
    Provides convenience behavior for drawing strings, underline chars, and accessing font metrics.

    Note: This class is not part of the public JGoodies Common API. It should be treated as library internal and should not be used by API users. It may be removed or changed without further notice.

    Author:
    Karsten Lentzsch
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void drawString​(javax.swing.JComponent c, java.awt.Graphics g, java.lang.String text, int x, int y)
      Draws the string at the specified location underlining the specified character.
      static void drawStringUnderlineCharAt​(javax.swing.JComponent c, java.awt.Graphics g, java.lang.String text, int underlinedIndex, int x, int y)
      Draws the string at the specified location underlining the specified character.
      static java.awt.FontMetrics getFontMetrics​(javax.swing.JComponent c, java.awt.Graphics g)
      Returns the FontMetrics for the current Font of the passed in Graphics.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • drawString

        public static void drawString​(javax.swing.JComponent c,
                                      java.awt.Graphics g,
                                      java.lang.String text,
                                      int x,
                                      int y)
        Draws the string at the specified location underlining the specified character.
        Parameters:
        c - JComponent that will display the string, may be null
        g - Graphics to draw the text to
        text - String to display
        x - X coordinate to draw the text at
        y - Y coordinate to draw the text at
      • drawStringUnderlineCharAt

        public static void drawStringUnderlineCharAt​(javax.swing.JComponent c,
                                                     java.awt.Graphics g,
                                                     java.lang.String text,
                                                     int underlinedIndex,
                                                     int x,
                                                     int y)
        Draws the string at the specified location underlining the specified character.
        Parameters:
        c - JComponent that will display the string, may be null
        g - Graphics to draw the text to
        text - String to display
        underlinedIndex - Index of a character in the string to underline
        x - X coordinate to draw the text at
        y - Y coordinate to draw the text at
      • getFontMetrics

        public static java.awt.FontMetrics getFontMetrics​(javax.swing.JComponent c,
                                                          java.awt.Graphics g)
        Returns the FontMetrics for the current Font of the passed in Graphics. This method is used when a Graphics is available, typically when painting. If a Graphics is not available the JComponent method of the same name should be used.

        Callers should pass in a non-null JComponent, the exception to this is if a JComponent is not readily available at the time of painting.

        This does not necessarily return the FontMetrics from the Graphics.

        Parameters:
        c - JComponent requesting FontMetrics, may be null
        g - Graphics Graphics
        Returns:
        the FontMetrics