2011-07-09 9 views

Respuesta

15

Para poner html en un JLabel, sería hacer que se vea algo como esto

JLabel label = new JLabel("<html><yourTagHere><yourOtherTagHere>this is your text</yourOtherTagHere></yourTagHere></html>"); 
6

Esto va a hacer el truco:

String labelText ="<html><FONT COLOR=RED>Red</FONT> and <FONT COLOR=BLUE>Blue</FONT> Text</html>"; 
JLabel coloredLabel =new JLabel(labelText); 
+0

Eso es un una buena forma de hacerlo también – Globmont

4

Existen las siguientes formas

  1. Usando el método SetText del objeto JLabel

    JLabel HTMLlabel = new JLabel().setText("<html><tag>blah blah</tag></html>");

  2. Pasando la cadena a la clase JLable Constructor.

    JLabel HTMLlabel = new JLabel("<html><tag>blah blah</tag></html>");

  3. Utilizando serie y pasándolo a constructor de la clase JLabel similar al anterior ejemplo pero utilizando de cadena.

    String HTMLlabelStr = "<html><tag>blah blah</tag></html>";
    JLabel HTMLlabel = new JLabel(HTMLlabelStr);

0

Esto debería hacer el truco:

JLabel whatever = 
    new JLabel("<html><something>Put Stuff Here</something></html>"); 
0
JLabel myHTMLLabel =new JLabel("<html>"); 
myHTMLLabel.setText("<html><font color='green'>Hello World</font>"); 
0

También usted puede usar esto con todos los botones Swing, elementos de menú, etiquetas, paneles de texto, hojas de editor, herramienta consejos, paneles con pestañas, etc. ...

JTextPane pane = new JTextPane(); 
pane.setContentType("text/html"); 

pane.setText("<html><h1>My First Heading</h1><p>My first paragraph.</p></body></html>");