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:

  • strikethrough text in java
  • how to underline words in java
  • how to underline string in java
  • underlining text in java
  • java font underline strikeout
  • strike through value java
  • underline in jlabel in java
  • jlabel shows middle of long text instead of beginning
  • java swing label html strikethrough
  • create+UnderLine+using+Font+in+java+swing

No comments yet.

Leave a Comment