Reputation: 109
I'm using JTextPane and JButton
If I click the Button, I hope every characters in JTextPane will have a dot under it
Is there any way to do this?
The big problem is how to add dots under every characters :(
Upvotes: 2
Views: 210
Reputation: 57391
http://java-sl.com/tip_colored_strikethrough.html you can use the example of colored strikethrough.
All you need is to draw your line under letters. Just set Stroke
to your Graphics2D
instance. (See BasicStroke
and dash pattern)
Upvotes: 1
Reputation: 28687
You can make use of javax.swing.text.DefaultHighlighter
, which handles character spacing of a text component in order to do background painting on that component.
public class DotHighlighter extends DefaultHighlighter {
// implementation
}
Implementing a custom highlighter is a moderate sized amount of work, but here's a nice code example of an underlining highlighter implementation; you should be able to modify it to draw dots.
Upvotes: 1
Reputation: 9382
Are you using a monospaced font? If so, it would be possible to create a new label and display a string that is composed only of periods (of the same length as the string in the original label), and display that label a bit lower than the first.
I.E., if your label says 2446
, then you could make a second label that's 5 or 10 pixels lower, which says ....
.
Again, this will only work with a monospaced font- for any other fonts, it would still be possible, but it would involve a more complicated solution (looping through each character, finding its location, and then managing to display a dot beneath it), I believe.
Upvotes: 0