2011-07-09 14 views

risposta

15

Per mettere HTML in un JLabel, si dovrebbe far sembrare qualcosa di simile

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

Questo farà il trucco:

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

buon modo per farlo anche – Globmont

4

ci sono modi seguenti

  1. Utilizzo del metodo SetText dell'oggetto JLabel

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

  2. Passing String to JLable class Constructor.

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

  3. Uso String e passarlo al JLabel classe di costruzione simile al precedente esempio ma utilizzando stringa.

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

0

Questo dovrebbe fare il trucco:

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

Inoltre è possibile utilizzare questo con tutti i pulsanti di Swing, voci di menu, etichette, riquadri di testo, editor di vetri, strumento suggerimenti, pannelli a schede, ecc ...

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

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