I want HIghlighted text to look bold
When I select a piec开发者_如何学编程e 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?
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"
Use a JTextPane, then you can use Styles for your hightlighted text. See the section from the Swing tutorial on Text Component Features.
精彩评论