Devi usare un oggetto particolare JTextPane
codice:
import java.awt.FlowLayout;
import javax.swing.BorderFactory;
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JTextField;
import javax.swing.JTextPane;
public class setForeground {
public static void main(String[] args) {
JFrame form=new JFrame();
form.setSize(500,500);
form.getContentPane().setLayout(new FlowLayout(FlowLayout.CENTER));
JTextPane text=new JTextPane();
form.getContentPane().add(text);
text.setContentType("text/html");
text.setText("<html> html html <font color=red> html </font></html>");
form.show();
}
}