Posted By:
dharmendra_dubey
Posted On:
Sunday, May 18, 2003 10:09 PM
if the document type of youe text area is html type the just put the text in html ... with whtever color you want (by using ) tag ,
m_txaHTML = new JTextArea(8,50);
m_txaHTML.setEditable(false);
m_txaHTML.setLineWrap(true);
m_scpHTML = new JScrollPane(m_txaHTML);
m_txpEditor = new JTextPane();
m_scpEditor = new JScrollPane(m_txpEditor);
m_scpEditor.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
m_scpEditor.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
m_txpEditor.setEditable(false);
m_txpEditor.setBackground(EDITOR_BACKGROUND);
//m_txaHTML.setSize(330,180);
m_txaHTML.setPreferredSize(new Dimension(240,250));
//m_scpHTML.setSize(330,180);
m_scpHTML.setPreferredSize(new Dimension(240,250));
//m_scpEditor.setSize(330,180);
m_scpEditor.setPreferredSize(new Dimension(240,250));
===================================================
Function code which set the editor type of the text area
String testHtml=txtStr;
javax.swing.text.html.HTMLEditorKit htmlEditorKit = new javax.swing.text.html.HTMLEditorKit();
javax.swing.text.html.HTMLDocument htmlDoc = (javax.swing.text.html.HTMLDocument)htmlEditorKit.createDefaultDocument();
m_txpEditor.setEditorKit(htmlEditorKit);
m_txpEditor.setDocument(htmlDoc);
StringReader sr=new StringReader(testHtml);
htmlEditorKit.read(sr,htmlDoc,0);
Posted By:
Bahman_Barzideh
Posted On:
Thursday, March 20, 2003 04:59 AM
JTextArea is monochrome. It supports one text (foreground) color on one background color.
If you need multi-color text (different text segments have different
foreground/background color) you should look into JTextPane or its parent JEditorPane.