List of utility methods to do Graphics Draw Multiline String
void | draw(String _str, Graphics2D _g2, int _nX0, int _nY0, int _nX1, int _nY1) draw Font font = new Font(getFontName(), Font.BOLD, getFontSize()); AttributedString str = new AttributedString(_str); str.addAttribute(TextAttribute.FONT, font); str.addAttribute(TextAttribute.FOREGROUND, getColor()); _g2.drawString(str.getIterator(), getNumber(_nX0, _nX1), (_nY0 + _nY1) * 2 / 3); |
void | drawMultilineString(Graphics g, String s, int alignment, Rectangle r, boolean print) Draws a multi line text and/or calculates the dimensions of the text when drawn into the given Graphics object. drawMultilineString(g, null, s, alignment, r, print); |
void | drawMultilineText(final Graphics2D gc, final int x, int y, final String text) Draw multi-line text final int line_height = gc.getFontMetrics().getHeight(); for (String line : text.split("\n")) { gc.drawString(line, x, y); y += line_height; |
void | drawMultiLineText(String text, Graphics G, int x, int y) draw Multi Line Text FontMetrics metrics = G.getFontMetrics(); StringTokenizer str = new StringTokenizer(text, "\n\r"); int height = y; while (str.hasMoreTokens()) { String token = str.nextToken(); G.drawString(token, x, height + metrics.getAscent()); height += (metrics.getAscent() + metrics.getLeading()); |
void | drawRightMultiLineText(String text, Graphics G, int x, int y) draw Right Multi Line Text FontMetrics metrics = G.getFontMetrics(); Dimension size = measureMultiLineText(text, G); StringTokenizer str = new StringTokenizer(text, "\n\r"); int height = y; while (str.hasMoreTokens()) { String token = str.nextToken(); G.drawString(token, x + size.width - metrics.stringWidth(token), height + metrics.getAscent()); height += (metrics.getAscent() + metrics.getLeading()); ... |
void | drawString(Graphics g, String s, int x, int y) draw String Graphics2D g2d = (Graphics2D) g.create(); g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); BasicGraphicsUtils.drawStringUnderlineCharAt(g2d, s, -1, x, y); |
void | drawStringBiggest(final Graphics2D g2d, final Dimension dim, final String drawString) Draw a given String to a graphic object as big as possible but still stay within given dimension. Rectangle2D bounds; Object KEY_ANTIALIASING_before = g2d.getRenderingHint(RenderingHints.KEY_ANTIALIASING); Object KEY_TEXT_ANTIALIASING_before = g2d.getRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF); int fontsize = (int) Math.max(6, Math.ceil(dim.getWidth() / drawString.length()) * 3); fontsize = Math.min(fontsize, (int) Math.ceil(dim.getHeight() * 1.3)); float posx = 0, posy = 0; ... |
void | drawStringUnderlineCharAt(Graphics g, String s, int underlinedIndex, int x, int y) draw String Underline Char At Graphics2D g2d = (Graphics2D) g.create(); g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); BasicGraphicsUtils.drawStringUnderlineCharAt(g2d, s, underlinedIndex, x, y); |
void | drawStyleString(final Graphics graphics, final String message, final int x, final int y, final Color color, final Color color1) draw Style String graphics.setColor(color); graphics.drawString(message, x + 1, y); graphics.drawString(message, x - 1, y); graphics.drawString(message, x, y + 1); graphics.drawString(message, x, y - 1); graphics.setColor(color1); graphics.drawString(message, x, y); |
void | drawTrimmedString(Graphics g, String s, int x, int y, int width) draw Trimmed String if (s == null) s = "" + s; FontMetrics fm = g.getFontMetrics(); int wordWidth = fm.stringWidth(s + " "); int charIdx = s.length(); boolean textTrimmed = false; while (charIdx > 0 && wordWidth >= width) { charIdx -= 1; ... |