List of utility methods to do Draw String
void | drawStringAt(Graphics g, String t, int x, int y, int where) _more_ FontMetrics fm = g.getFontMetrics(); int w = fm.stringWidth(t); int h = fm.getMaxAscent() + fm.getMaxDescent(); switch (where) { case PT_NW: g.drawString(t, x, y + h); break; case PT_NE: ... |
void | drawStringAtPoint(Graphics g, String s, Point p) Draws a String on the screen using a Point instead of x y g.drawString(s, p.x, p.y); |
void | drawStringEx(Graphics g1, String s, Font font, Rectangle rect, int align, int valign) draw String Ex Graphics2D g = (Graphics2D) g1; g.setFont(font); FontMetrics fm = g.getFontMetrics(); Dimension ret = new Dimension(fm.stringWidth(s), fm.getHeight()); float x = 0; float y = 0; if (align > 0) { x = (rect.x + rect.width) - ret.width; ... |
void | drawStringInBox(Graphics g, String string, int x, int y) draw String In Box Color color = g.getColor(); FontMetrics metrics = g.getFontMetrics(); y -= metrics.getAscent(); int width = metrics.stringWidth(string); int height = metrics.getHeight(); g.setColor(Color.WHITE); g.fillRect(x, y, width + 6, height + 6); g.setColor(color); ... |
void | drawStringLeft(Graphics2D g, String text, Rectangle rect, int fontHeight, Color c) draw String Left Font f = new Font("Serif", Font.PLAIN, fontHeight); g.setFont(f); g.setColor(c); g.drawString(text, rect.x, rect.y + rect.height); |
Image | drawStringOnImage(Image image, String string, int x, int y) draw String On Image BufferedImage image1 = toBufferedImage(image);
Graphics2D g = image1.createGraphics();
g.drawString(string, x, y);
return image1;
|
void | drawStringOnScreen(String s, Color color, long milseconds) draw String On Screen Thread t = new Thread(() -> { Window w = new Window(null) { @Override public void paint(Graphics g) { final Font font = getFont().deriveFont(48f); g.setFont(font); g.setColor(color); final String message = s; ... |
void | drawStringPair(Graphics2D g, String str1, String str2, int left, int right, int y, int size, Color color, boolean bold) draw String Pair drawStringLeft(g, str1, left, y, size, color, bold); drawStringRight(g, str2, right, y, size, color, bold); |
void | drawStringRight(final Graphics g, final FontMetrics m, final String str, final int x, final int y) draw String Right g.drawString(str, x - m.stringWidth(str), y); |
void | drawStringRightAlignedVTop(Graphics graphics, String string, int x, int yTop) draw String Right Aligned V Top Rectangle2D rect = graphics.getFontMetrics().getStringBounds(string, graphics); int xx = (int) (x - rect.getWidth()); int yy = (int) (yTop + rect.getHeight()); graphics.drawString(string, xx, yy); |