swing - Java add global JTextPane styles/attributes? -


i want add global attributeset jtextpane.

i found this:

simpleattributeset style = new simpleattributeset(); styleconstants.setleftindent(style, 20); styleconstants.setfirstlineindent(style, -20); 

from http://java-sl.com/tip_hanging_first_line.html

i'm wondering how can set "default stylesheet"? (not using html). tried this:

stylecontext style = new stylecontext(); style s = style.addstyle("test", null); styleconstants.setforeground(s, color.blue); styleddocument d = (styleddocument) console.getoutputfield().getdocument(); 

from http://www.java2s.com/code/java/swing-jfc/jtextpanestylesexample1.htm without luck.

i know styleddocument has specific properties setting stuff foreground colour - why may not work - can point me how use other style attributes? such left indent , first line indent.

jtextpane textpane = new jtextpane(); styleddocument doc = textpane.getstyleddocument(); simpleattributeset style = new simpleattributeset(); styleconstants.setleftindent(style, 20); styleconstants.setfirstlineindent(style, -20); styleconstants.setforeground(style, color.blue); doc.setparagraphattributes(0, doc.getlength(), style, true); 

Comments