HTML in JtextPane JAVA

0

I have a little doubt, how do I print a string inside a Text Panel with html tags?

Example:

jtextpane.setText("<html><body><font color=#16a085 size=6> Hola a todos! </font></body></html>");

@Dev. Joel Aca attached the code

JFrame 1

private void impMouseClicked(java.awt.event.MouseEvent evt) { 
linkedHashSet.addAll(arreglo);
        arreglo.clear();
        arreglo.addAll(linkedHashSet);


       String a="";

    for(int x=0; x<arreglo.size(); x++){

            a+=arreglo.get(x) +" " + arr.get(x)+"\n"; 

     }

        try {
            rs.impre(a);


        } catch (JessException ex) {
            Logger.getLogger(test_v.class.getName()).log(Level.SEVERE, null, ex);
        }
       imp.setVisible(false);}

JFrame2

 public void impre(String res) throws JessException {
    this.setVisible(true);
    jtimp.setContentType("text/html");
    jtimp.setText("<html><body><font color=#16a085 size=6><b>"
            + "A continuación se muestra el recorrido del árbol:<br> Síntomas: "
            + "Respuesta: <br></b></font>"+res+"</body></html>");


    }
    
asked by Jesus Duarte 07.10.2017 в 21:41
source

1 answer

1

As you are doing it is fine, but with additional configuration, you must assign the content type of JTextPanel using setContentType (" text / html ")

jtextpane.setContentType("text/html");
jtextpane.setText("<html><body><font color=#16a085 size=6> Hola a todos! </font></body></html>");

Tabs (\ t) and line breaks (\ n) are not recognized in HTML , so it will not show the format you want, the first change would be to replace the jumps and tabulations with HTML .

 String a="";

for(int x=0; x<arreglo.size(); x++){
   a+=arreglo.get(x) +" &#09; " + arr.get(x)+" <br>"; 
 }
    
answered by 07.10.2017 / 23:03
source