JLabel
- JLabel mở rộng JComponent cung cấp hướng dẫn văn bản hoặc thông tin trên GUI.
- Hiển thị một dòng text chỉ đọc, hình ảnh hoặc cả hai.
- Có thể hiển thị văn bản một dòng với màu và font khác nhau dùng thẻ <font size='font-size' color='color of the text'> Some Text </font> bên trong thẻ HTML.
- Có thể tạo giao diện PropertyChangeListener.
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(" Welcome to Tutorials Point");
add(label);
setSize(375, 250);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
setVisible(true);
}
public static void main(String[] args) {
new MultiColorLabelTest();
}
}
Kết quả
