java - JTextPane Coloured Words Not working -
so created simple jframe , added jtextpane create sorta console..
i have following methods , variables in class supposed change colour of text in jtextpane.
private static final object currentconsoleattributes[] = new object[4]; private static final simpleattributeset consoleattributes = new simpleattributeset(); public object[] getconsoleattributes() { currentconsoleattributes[0] = styleconstants.getforeground(consoleattributes); currentconsoleattributes[1] = styleconstants.getbackground(consoleattributes); currentconsoleattributes[2] = styleconstants.isbold(consoleattributes); currentconsoleattributes[3] = styleconstants.isitalic(consoleattributes); return currentconsoleattributes; } public void setconsoleattributes(color foreground, color background, boolean bold, boolean italics) { synchronized(consoleattributes) { styleconstants.setforeground(consoleattributes, foreground); styleconstants.setbackground(consoleattributes, background); styleconstants.setbold(consoleattributes, bold); styleconstants.setitalic(consoleattributes, italics); } } private void setoutputareatext(final string text) { swingutilities.invokelater(new runnable() { //i read need use when dealing swing , jtextpane swing component. @override public void run() { try { styleddocument document = frame.this.outputarea.getstyleddocument(); document.insertstring(document.getlength(), text, consoleattributes); } catch (badlocationexception e) { e.printstacktrace(); } } }); } public void writeline(object value) { try { system.out.print("hey"); setconsoleattributes(java.awt.color.red, color.white, true, false); system.out.print("testing"); setconsoleattributes(java.awt.color.blue, color.white, true, false); system.out.println("printing"); } catch (exception ex) { ex.printstacktrace(); } } however, when call writeline, entire line written in blue or whatever colour used last. ideas i'm missing?
Comments
Post a Comment