• Post Reply Bookmark Topic Watch Topic
  • New Topic

JTextPane vs AWT TextArea  RSS feed

 
CitySlicker
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does anyone know of an easy way to append text to a JTextPane component?
TextArea in awt had some nice methods to add text, not just replace text.
Unfortunately, I am unable to find a way to add text to a JTextPane without replacing the previous text. Any suggestions?
 
Sajee Joseph
Ranch Hand
Posts: 200
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
juzz do
DefaultStyledDocument doc = new DefaultStyledDocument();
JTextPane tp = new JTextPane(doc);
String msg = "Hello";
aset = new SimpleAttributeSet();
//set bold and red
StyleConstants.setForeground(aset,Color.red);
StyleConstants.setBold(aset,true);
doc.insertString(doc.getLength(), msg,aset);
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!