You must use Swing timers for this. Do not interact with GUI objects from external threads.
There are some documents in the Java tutorial: How to use Swing timers .
Here is an example of how you could play with the button icon.
// in constructor for example buttonIcon = new ImageIcon("resources/icon.png"); button.setIcon(buttonIcon); timer = new Timer(1000, this); timer.start();
// in the actionPerformed handler if (button.getIcon() == null) button.setIcon(icon); else button.setIcon(null);
To do this, you will need to implement an ActionListener for it to work like this. Add some logic to stop blinking when you need it.
source share