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:

  1. §a color.gethsbcolor(0.333f, 1.000f, 1.000f);
  2. §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

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -