java - Use color codes for programmatically formatting a String -
i have sixteen character pairs (e.g. §c, each code starts § , followed 0-9 or a-f) represent java.awt.color. here's 2 examples:
- §a color.gethsbcolor(0.333f, 1.000f, 1.000f);
- §6 color.gethsbcolor(0.167f, 1.000f, 0.502f);
i need way set color of string combination of these colors.
example: §athis text green, §6this text gold. formatted: <green>this text green, <gold>this text gold
note <> tags examples, need use following method set color in jtextpane:
public void append(color c, string s) { try { simpleattributeset sas = new simpleattributeset(); styleconstants.setforeground(sas, c); this.getdocument().insertstring(getdocument().getlength(), s, sas); } catch (badlocationexception ex) { ex.printstacktrace();} }
so far no methods of mine have worked. i've seen several close questions, none relating changing text depending on 'color codes'.
tl;dr - need method programmatically inserting formatted text jtextpane using color codes.
Comments
Post a Comment