水平…
String text = "...";Graphics2D g2d = (Graphics2D)g.create();FontMetrics fm = g2d.getFontMetrics();int x = (getWidth() - fm.stringWidth(text)) / 2;
垂直…
String text = "...";Graphics2D g2d = (Graphics2D)g.create();FontMetrics fm = g2d.getFontMetrics();int y = ((getHeight() - fm.getHeight()) / 2) + fm.getAscent();
也在这里展示
还可以看一下2D图形和使用文本API



