List of usage examples for java.text AttributedString AttributedString
public AttributedString(AttributedCharacterIterator text)
From source file:Main.java
public static int paintMultilineText(Graphics2D g2d, String text, int textX, int textWidth, int textY, int maxTextLineCount) { FontRenderContext frc = new FontRenderContext(new AffineTransform(), true, false); int fa = g2d.getFontMetrics().getAscent(); if (text.length() == 0) return textY; int currOffset = 0; AttributedString attributedDescription = new AttributedString(text); attributedDescription.addAttribute(TextAttribute.FONT, g2d.getFont()); LineBreakMeasurer lineBreakMeasurer = new LineBreakMeasurer(attributedDescription.getIterator(), frc); int lineCount = 0; while (true) { TextLayout tl = lineBreakMeasurer.nextLayout(textWidth); if (tl == null) break; int charCount = tl.getCharacterCount(); String line = text.substring(currOffset, currOffset + charCount); g2d.drawString(line, textX, textY); textY += fa;//from ww w . j av a2 s . c om currOffset += charCount; lineCount++; if ((maxTextLineCount > 0) && (lineCount == maxTextLineCount)) break; } // textY += fh; return textY; }
From source file:Main.java
public void paint(Graphics g) { Graphics2D g2d = (Graphics2D) g; AttributedString astr = new AttributedString("aString"); astr.addAttribute(TextAttribute.FONT, new Font("", 1, 30), 1, 2); astr.addAttribute(TextAttribute.BACKGROUND, Color.red, 2, 3); TextLayout tl = new TextLayout(astr.getIterator(), g2d.getFontRenderContext()); tl.draw(g2d, 10, 20);/*w w w. j a va2s . com*/ }
From source file:Main.java
public void paint(Graphics g) { Graphics2D g2d = (Graphics2D) g; g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); AttributedString as1 = new AttributedString("1234567890"); as1.addAttribute(TextAttribute.STRIKETHROUGH, TextAttribute.STRIKETHROUGH_ON, 2, 8); g2d.drawString(as1.getIterator(), 15, 60); }
From source file:Main.java
public void paint(Graphics g) { Graphics2D g2d = (Graphics2D) g; g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); AttributedString as1 = new AttributedString("1234567890"); as1.addAttribute(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON, 3, 4); g2d.drawString(as1.getIterator(), 15, 60); }
From source file:BasicShapes.java
public void paint(Graphics g) { Graphics2D g2d = (Graphics2D) g; int x = 10, y = 10, start = 2, end = 4; AttributedString astr = new AttributedString("aString"); astr.addAttribute(TextAttribute.FONT, new Font("", 1, 1), start, end); astr.addAttribute(TextAttribute.BACKGROUND, Color.red, start, end); // Draw mixed-style text TextLayout tl = new TextLayout(astr.getIterator(), g2d.getFontRenderContext()); tl.draw(g2d, x, y);//from w ww . ja v a2s.c om }
From source file:TextAttributesSize.java
public void paint(Graphics g) { Graphics2D g2d = (Graphics2D) g; g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); AttributedString as1 = new AttributedString("1234567890"); as1.addAttribute(TextAttribute.SIZE, 40); g2d.drawString(as1.getIterator(), 15, 60); }
From source file:TextAttributesColor.java
public void paint(Graphics g) { Graphics2D g2d = (Graphics2D) g; g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); AttributedString as1 = new AttributedString("1234567890"); as1.addAttribute(TextAttribute.FOREGROUND, Color.red, 0, 2); g2d.drawString(as1.getIterator(), 15, 60); }
From source file:TextAttributesBackground.java
public void paint(Graphics g) { Graphics2D g2d = (Graphics2D) g; g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); AttributedString as1 = new AttributedString("1234567890"); as1.addAttribute(TextAttribute.BACKGROUND, Color.LIGHT_GRAY, 2, 9); g2d.drawString(as1.getIterator(), 15, 60); }
From source file:TextAttributesSuperscript.java
public void paint(Graphics g) { Graphics2D g2d = (Graphics2D) g; g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); AttributedString as1 = new AttributedString("1234567890"); as1.addAttribute(TextAttribute.SUPERSCRIPT, TextAttribute.SUPERSCRIPT_SUPER, 5, 7); g2d.drawString(as1.getIterator(), 15, 60); }
From source file:Main.java
License:asdf
void drawParagraph(Graphics2D g, String paragraph, float width) { LineBreakMeasurer linebreaker = new LineBreakMeasurer(new AttributedString(paragraph).getIterator(), g.getFontRenderContext());/* w w w . ja v a2 s .co m*/ int y = 0; while (linebreaker.getPosition() < paragraph.length()) { TextLayout textLayout = linebreaker.nextLayout(width); y += textLayout.getAscent(); textLayout.draw(g, 0, y); y += textLayout.getDescent() + textLayout.getLeading(); } }