Results 1 to 1 of 1
-
How to use TextAttribute class to obtain underlined and striked through text
Java Code:import java.awt.Font; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.RenderingHints; import java.awt.font.TextAttribute; import java.text.AttributedString; import javax.swing.JFrame; import javax.swing.JPanel; public class IteratorUnderStrike extends JPanel{ public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; String s = "\"www.java2s.com\" is great."; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); Font plainFont = new Font("Times New Roman", Font.PLAIN, 24); AttributedString as = new AttributedString(s); as.addAttribute(TextAttribute.FONT, plainFont); as.addAttribute(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON, 1, 15); as.addAttribute(TextAttribute.STRIKETHROUGH, TextAttribute.STRIKETHROUGH_ON, 18, 25); g2.drawString(as.getIterator(), 24, 70); } public static void main(String[] args) { JFrame f = new JFrame(); f.getContentPane().add(new IteratorUnderStrike()); f.setSize(850, 250); f.show(); } }"The sole cause of man’s unhappiness is that he does not know how to stay quietly in his room." - Blaise Pascal
Similar Threads
-
How to obtain ASCII code of a character
By karma in forum New To JavaReplies: 4Last Post: 07-20-2008, 02:57 AM -
How to use TextAttribute class to change color and font of a text
By Java Tip in forum java.awtReplies: 0Last Post: 06-25-2008, 10:33 AM -
Unsupported Content-Type: text/html Supported ones are: [text/xml]
By luislopezco in forum Advanced JavaReplies: 0Last Post: 05-26-2008, 04:26 PM -
Edit JPanel Text During Runtime...from another class
By bdn1404 in forum New To JavaReplies: 5Last Post: 08-11-2007, 03:14 AM -
Struts, Some API to obtain wide and the high one of an image?
By Eric in forum Web FrameworksReplies: 1Last Post: 06-07-2007, 05:06 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks