1
我可以用一個定時器淡出正常的JLabel一個JLabel,如下:衰落包含HTML
public static void main(String[] args) {
JFrame frame = new JFrame();
// final JLabel label = new JLabel("<html><font color=red>Red</font><font color=blue>Blue</font>");
final JLabel label = new JLabel("Hello");
label.setOpaque(true);
label.setBackground(Color.WHITE);
frame.getContentPane().add(label);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
final Timer timer = new Timer(100, null);
final int steps = 25;
timer.addActionListener(new ActionListener() {
int count = 0;
public void actionPerformed(ActionEvent e) {
if (count <= steps) {
float intensity = count/(float) steps;
label.setForeground(new Color(intensity, intensity, intensity));
count++;
} else {
timer.stop();
}
}
});
timer.start();
}
我怎樣才能讓這個還與包含HTML一個JLabel工作,按照被註釋掉線?
final JLabel label = new JLabel("<html><font color=red>Red</font><font color=blue>Blue</font>");