JLabel
- A JLabel lớp có thể mở rộng JComponent lớp và một đối tượng của JLabel cung cấp hướng dẫn văn bản hoặc thông tin trên GUI.
- A JLabel có thể hiển thị một dòng văn bản chỉ đọc , một hình ảnh hoặc cả văn bản và hình ảnh.
- A JLabel cũng có thể hiển thị một dòng văn bản với màu sắc và phông chữ khác nhau sử dụng Một số Văn bản bên trong một HTML thẻ.
- A JLabel có thể tạo PropertyChangeListener một cách rõ ràng giao diện.
Ví dụ
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class MultiColorLabelTest extends JFrame {
public MultiColorLabelTest() {
setTitle("MultiColorLabel Test");
setLayout(new FlowLayout());
// multi colored with different font size label
JLabel label = new JLabel("<html><font size='5' color=blue> Welcome to</font> <font size='6'color=green> Tutorials Point</font></html>");
add(label);
setSize(375, 250);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
setVisible(true);
}
public static void main(String[] args) {
new MultiColorLabelTest();
}
} Đầu ra