问题
I am trying to add some code to myHighlighter class so that i can highlight and turn BOLD the part of the text i want.My first try was not successful..
Highlighter.HighlightPainter myHighlightPainter =
new MyHighlightPainter(Color.red,Font.BOLD);
class MyHighlightPainter extends DefaultHighlighter.DefaultHighlightPainter {
public MyHighlightPainter(Color color, int Font) {
super(color);
}
Also i am trying to avoid Graphics...
回答1:
Have you tried setting the text to HTML? I believe the JTextPane
supports HTML, so try setting your text to something like:
myTextPane.setText("<html>This text box has <b>bold text</b> in it!</html>");
来源:https://stackoverflow.com/questions/8400913/highlight-and-bold-text-in-jtextpane