I have 100 same JPanels, each contains JLabel with an icon and JLabel with text. When certain event occurs, I want to change icon and border of panel for 2.5 seconds, and then change them back. The problem is that 1st they are changed together, but when I try to change them back - first icon is changed, and then in 2 or 3 seconds border is changed. Here is the method of a JPanel to perform this:
public void showPacketCame() {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
img.setIcon(blue);
setBorder(BorderFactory.createLineBorder(new Color(54, 208, 243)));
javax.swing.Timer tim = new javax.swing.Timer(2500, new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
img.setIcon(onDark);
setBorder(null);
}
});
tim.setRepeats(false);
tim.setDelay(2500);
tim.start();
}
});
}