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
{filelink=9438}

  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();
				g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
				RenderingHints.VALUE_ANTIALIAS_ON);
				// 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);
				}
		};
		f.setSize(500,150);
		f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		f.setLocationRelativeTo(null);
		f.setVisible(true);
	   }
}

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