简体   繁体   中英

How to strike any letter using Unicode in Java

In my Java application I want to output striked letters (like html tag do). Is there any way to do this using Unicode (combine )

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.

如前所述,Unicode不会这样做,但很多Swing组件都能理解基本的HTML标签。

JLabel label = new JLabel("<html><s>My stroke</s></html>")

No. Unicode does not define a combining strikeout mark. Unicode's view is that this is the job of markup -- like HTML.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM