Java JLabel set text color via HTML

Description

Java JLabel set text color via HTML

import java.awt.BorderLayout;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class Main extends JFrame {

  public static void main(String[] args) {
    String lyrics = "<html><center><b>Label 1</b><br>"
        + "<font color=#7f7fdd>Bold</font>";

    JPanel panel = new JPanel();
    panel.setLayout(new BorderLayout(10, 10));

    JLabel label = new JLabel(lyrics);

    panel.add(label, BorderLayout.CENTER);

    JFrame f = new JFrame();
    f.add(panel);//  w w w .jav a 2  s.  c o m
    f.pack();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setVisible(true);
  }
}



PreviousNext

Related