Reputation: 13274
When I select a piece of text in a JTextArea, it gets coloured in white and highlighted in blue (I'm using Nimbus LookAndFeel).
I changed it so the highlight is white, and the text also remains in black, so it is not noticed. What I want now is to get the text in bold when the user highlights it.
Is there any easy way to do this? Would it work if I create a listener for double-click, or would the text get bold but not highlighted at all?
Upvotes: 1
Views: 267
Reputation: 324197
Use a JTextPane, then you can use Styles for your hightlighted text. See the section from the Swing tutorial on Text Component Features.
Upvotes: 1
Reputation: 57421
See DefaultHighlighter
source
Inner class DefaultHighlightPainter
has method
public void paint(Graphics g, int offs0, int offs1, Shape bounds, JTextComponent c)
You can specify font there. Just call setFont() for the Graphics instance.
NOTE: bold font could have different widht so you should use font like "Monospaced"
Upvotes: 1