java - Changing color character text of a JLabel? -
i'm trying changing color character text of jlabel.
i have jlabel
text: "jlabel" , want alter color character "l". after change, want display text "jlabel" character "l" changed.
how can ?
i'm trying this:
private void characterformat(){ jlabel.settext("jlabel"); char[] t = jlabel.gettext().tochararray(); string txtformat = ""; for(int x = 0; x < t.length; x++){ if(t[x] == 'l'){ txtformat += string.format("<html><font color=red>%s</font></html>", t[x]); } } jlabel.settext(txtformat); }
i'm not sure if understand question correct. alter jlables text , highlighting 'l' character in reddish can following:
string text = jlabel.gettext(); text = "<html><body>" + text.replaceall("l", "<span style=\"color:red\">l</span>") + "</body></html>"; jlabel.settext(text);
java html swing jlabel
No comments:
Post a Comment