Powered by Ajaxy
Digg StumbleUpon LinkedIn YouTube Flickr Facebook Twitter RSS Reset

Java: Example of an underline and strikethrough text

Java: Example of an underline and strikethrough text

  import java.awt.*;
  import java.awt.font.TextAttribute;
  import java.text.*;
  import javax.swing.*;
  public class AttributText
		 public static void main(String[] args)
		   JFrame f = new JFrame("Strikethrough text")
				public void paint(Graphics g)
				Graphics2D g2 = (Graphics2D)g;
				String texte = "Exemples Java et Python";
				Dimension d = getSize();
				// Create a font
				Font font = new Font("Times New Roman", Font.PLAIN, 24);
				AttributedString str_attribut = new AttributedString(texte);
				// Apply the font to the text
				str_attribut.addAttribute(TextAttribute.FONT, font);
				// Undeline the text
				str_attribut.addAttribute(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON, 0, 8);
				// strikethrough text
				str_attribut.addAttribute(TextAttribute.STRIKETHROUGH, TextAttribute.STRIKETHROUGH_ON,
											 17, texte.length());
				g2.drawString(str_attribut.getIterator(), 40, 80);

Users who found this page were searching for:

  • how to add underline to text file with java
  • java font underline color
  • underline+text+in+jpanel+java
  • how to underline a label in java programming
  • java font underline
  • format string in java strikethrough
  • display an attributedstring in jtextarea
  • java font underline with example
  • how to underline string in java
  • how to underline a string in java

No comments yet.

Leave a Comment