AbstractGridElement.java 文件源码

java
阅读 24 收藏 0 点赞 0 评论 0

项目:Push2Display 作者:
/**
 * Draws a text into a boundary. The text is clipped on the right border of the bounds.
 *
 * @param g The graphics context in which to draw
 * @param text The text to draw
 * @param x The x position of the boundary
 * @param y The y position of the boundary
 * @param width The width position of the boundary
 * @param height The height position of the boundary
 * @param alignment The alignment of the text: Label.LEFT or Label.CENTER
 * @param textDescent Text text descent
 */
public static void drawTextInBounds (final Graphics2D g, final String text, final int x, final int y, final int width, final int height, final int alignment, final int textDescent)
{
    if (text == null || text.length () == 0)
        return;
    final Dimension dim = getTextDims (g, text);
    g.clipRect (x, y, width, height);
    final int pos;
    switch (alignment)
    {
        case Label.LEFT:
            pos = x;
            break;

        case Label.CENTER:
        default:
            pos = x + (width - dim.width) / 2;
            break;
    }
    g.drawString (text, pos, y + height - (height - dim.height) / 2 - textDescent);
    g.setClip (null);
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号