How can I set partial text color in JTextArea?

后端 未结 2 1146
挽巷
挽巷 2021-01-22 05:04

I want to set color for specific lines in the text area. What I\'ve found so far, is the following

// Declarations
private final DefaultStyledDocument document;         


        
2条回答
  •  天涯浪人
    2021-01-22 05:40

    I'm not sure if JTextArea can be styled in so much detail, since it presumably sets up styles for the whole document from the selected font, color etc. You may have more luck using a JTextPane/JEditorPane.

    EDIT: From the javadoc

    A JTextArea is a multi-line area that displays plain text.

    (The emphasis is added.)

    If you can move to JTextPane, then that will render the formatting.

提交回复
热议问题