All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.spun.swing.SwingUtils Maven / Gradle / Ivy

There is a newer version: 24.9.0
Show newest version
package com.spun.swing;

import java.awt.FontMetrics;
import java.awt.Graphics;

public class SwingUtils
{
  public static void drawCenteredString(Graphics g, String text, int x, int y)
  {
    FontMetrics metrics = g.getFontMetrics();
    int width = metrics.stringWidth(text);
    x -= (width / 2);
    int height = metrics.getHeight();
    y -= (height / 2);
    y += metrics.getAscent();
    g.drawString(text, x, y);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy