public void paint(Graphics g) {
Graphics2D g2d = (Graphics2D)g;
Font font = new Font("Serif", Font.PLAIN, 12);
FontMetrics fontMetrics = g2d.getFontMetrics();
int width = fontMetrics.stringWidth("1234abcd");
int height = fontMetrics.getHeight();
}