2011-07-09 18 views

Odpowiedz

15

Aby umieścić html w JLabel, by zrobić to wyglądać mniej więcej tak

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

będzie to rade:

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

Thats a całkiem dobry sposób, aby to zrobić – Globmont

4

Istnieją następujące sposoby

  1. Metoda SetText obiektu JLabel Obiekt

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

  2. Przekazywanie łańcucha do konstruktora klasy JLable.

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

  3. Korzystanie String i przekazaniem go do konstruktora klasy JLabel podobny do przykładu powyżej, ale stosując String.

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

0

To powinno załatwić sprawę:

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

Ponadto można korzystać z tego ze wszystkich przycisków huśtawka, pozycji menu, etykiet, okienek tekstowych, szyb redaktor, narzędzia wskazówki, tace z zakładkami itp.

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

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