List of utility methods to do Draw String
void | drawStringUnderlineCharAt(Graphics g, String text, int underlinedIndex, int x, int y) Draw a string with the graphics g at location ( x , y ) just like g.drawString would. g.drawString(text, x, y); if (underlinedIndex >= 0 && underlinedIndex < text.length()) { FontMetrics fm = g.getFontMetrics(); int underlineRectX = x + fm.stringWidth(text.substring(0, underlinedIndex)); int underlineRectY = y; int underlineRectWidth = fm.charWidth(text.charAt(underlinedIndex)); int underlineRectHeight = 1; g.fillRect(underlineRectX, underlineRectY + fm.getDescent() - 1, underlineRectWidth, ... |
void | drawStringVCentered(Graphics graphics, String string, int x, int upperY, int lowerY) Draw a string vertically centered between upper and lower y left aligned to x. Rectangle2D rect = graphics.getFontMetrics().getStringBounds(string, graphics); int yy = (int) upperY + (lowerY - upperY) / 2 + (int) rect.getHeight() / 2; graphics.drawString(string, x, yy); |
void | drawStringVertical(Graphics graphics, String string, int x, int y) Draw a String vertical. Rectangle2D rect = graphics.getFontMetrics().getStringBounds(string, graphics); BufferedImage img = new BufferedImage((int) rect.getWidth(), (int) rect.getHeight(), BufferedImage.TYPE_3BYTE_BGR); Graphics imageGraphics = img.getGraphics(); imageGraphics.setColor(Color.WHITE); imageGraphics.fillRect(0, 0, img.getWidth(), img.getHeight()); imageGraphics.setColor(Color.BLACK); imageGraphics.drawString(string, 0, (int) rect.getHeight()); ... |
void | drawStringWithHighlighting(Graphics g, String s, int x, int y, Color foreground, Color highlighting) draw String With Highlighting g.setColor(highlighting); for (int i = x - 1; i <= x + 1; i++) { for (int j = y - 1; j <= y + 1; j++) { g.drawString(s, i, j); g.setColor(foreground); g.drawString(s, x, y); ... |