In my Java application I want to output striked letters (like html tag do). Is there any way to do this using Unicode (combine )
To strikethrough a text or a symbol, type a letter and put a special hyphen next ̶. In Unicode this character is called «Combining Long Stroke Overlay». Done!
Unicode character literals To print Unicode characters, enter the escape sequence “u”. Unicode sequences can be used everywhere in Java code. As long as it contains Unicode characters, it can be used as an identifier.
You can add underline and strikethrough text using the Chunk class, and its setUnderline() method. You use a negative underline value to get the line lower below the text, and a positive underline value to get the line to strike through the text.
You can use U+0336, the combining long stroke overlay, to accomplish this task.
For comparison, here is what U+0336 looks like compared to html's <strike>
tag:
U̶n̶i̶c̶o̶d̶e ̶c̶o̶m̶b̶i̶n̶i̶n̶g̶ ̶l̶o̶n̶g̶ ̶s̶t̶r̶o̶k̶e̶ ̶o̶v̶e̶r̶l̶a̶y̶
Hypertext strike tag
One thing to note though: If you look carefully at the "m" in "combining" above, you will probably see a small gap in the strike, due to the way combining overlay marks work. For this reason you should still prefer using html or some other technology over U+0336 for this purpose, if you have that option.
No, this is not possible. While there is the concept of a stroke as diacritic, it's not available as a separate Unicode character, probably because the various letters that use a stroke diacritic do not place it at the same height or even angle. So the result would not resemble strikethrough markup anyway.
To output strikethrough text in Java, you need to use an output format that allows you to use explicit markup. If you have a Swing app, you're in luck as many Swing components support HTML. Otherwise it depends on what presentation technology you're using.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With