Reputation: 13
I am having problems adding a HTML strike-through tag to a string of text in Java.
EDIT: I have posted the entire code and I am using Windows 7, Java 8 and Swing.
JLabel LocalSelectorLabel = new JLabel("<html><strike>Text Here</strike><html>");
LocalSelectorLabel.setBounds(12, 50, 55, 16);
LocalTabPanel.add(LocalSelectorLabel);
I have tried the tags: s, del and strike but all of them just give me underlined text. I have looked around for other tags that might work but I haven't found anything.
EDIT 2: This works for me, thanks:
new JLabel("<html><body><span style='text-decoration: line-through;'>Text Here</span></body></html>");
EDIT 3: Now this is interesting. I ran the code on a different computer and that one displays as strike-through and as underline as expected while the computer I used to ask this question did not. I see now why I didn't find anything when I searched for a solution.
Upvotes: 0
Views: 1869
Reputation: 15250
Be aware that <strike>
tag is not part of HTML5, you should use CSS to achieve this.
EDIT : you're using Swing, so HTML 3.2 and <strike>
tag exists (but still not recommended for future updates).
Upvotes: 1
Reputation: 168835
"<html></strike>Text Here</strike><html>"
Should be:
"<html><strike>Text Here</strike><html>"
The 'opening' </strike>
tag should be <strike>
.
As an aside, it never hurts to check the HTML using an HTML validator. For 'Swing HTML' set it to HTML 3.2 (or 4.01 transitional, if they stop supporting 3.2).
Upvotes: 8
Reputation: 21710
As a continue of @Gaël answer, using css you can achive your desired result with the follwing code:
new JLabel("<html><body><span style='text-decoration: line-through;'>Text Here</span></body></html>");
Upvotes: 5