How to change the color of specific words in a JTextPane?
问题 How do I change the color of specific words in a JTextPane just while the user is typing? Should I override JTextPane paintComponent method? 回答1: Overwriting paintComponent will not help you. This is not an easy one, but not impossible either. Something like this will help you: DefaultStyledDocument document = new DefaultStyledDocument(); JTextPane textpane = new JTextPane(document); StyleContext context = new StyleContext(); // build a style Style style = context.addStyle("test", null); //