BitmapFont (Font font) { font = font.deriveFont(FONT_SIZE); int imageWidth = CHAR_WIDTH * NUM_CHARACTERS; //noinspection UndesirableClassUsage BufferedImage image = new BufferedImage(imageWidth, CHAR_HEIGHT, BufferedImage.TYPE_BYTE_BINARY); Graphics2D g = image.createGraphics(); g.setColor(Color.white); g.fillRect(0, 0, imageWidth, CHAR_HEIGHT); g.setColor(Color.black); g.setFont(font); char[] c = new char[1]; for (c[0] = 0; c[0] < NUM_CHARACTERS; c[0]++) { if (font.canDisplay(c[0])) { int x = c[0] * CHAR_WIDTH; g.setClip(x, 0, CHAR_WIDTH, CHAR_HEIGHT); g.drawChars(c, 0, 1, x, CHAR_HEIGHT - CHAR_DESCENT); } } g.dispose(); return new BitmapFont(image); }