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 underline a java label using html tags
  • java.awt.font.textattribute underline example
  • how to set strikethrough label in bb java
  • create+UnderLine+using+Font+in+java+swing
  • how+to+use+strikethrough+swing
  • java jlabel underline text
  • how to set the underline font of text on jlabel in java
  • how to display strike characters in java + strikethrough on example
  • how to print strikethroughs in java
  • java method strikethrough

No comments yet.

Leave a Comment