I have a JButton
which, when pressed, changes background color from active to normal:
final Color activeButtonColor = new Color(159, 188, 191);
final Color normalButtonColor = new Color(47, 55, 56);
I want to fade the active button color back to the normal button color when a specific task has finished executing. I'm using SwingWorker
and wondered if anybody could suggest an efficient way to do this please?
button.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent event) {
new SwingWorker<Object, Object>() {
protected Object doInBackground() throws Exception {
button.setBackground(activeButtonColor);
for (int note = 60; note < 120; note++) {
midiController.sendMidiMessage(1, note, 83);
midiController.stopMidiMessage(note, 83);
}
Thread.sleep(200);
return null;
}
protected void done() {
try {
Object result = get();
// Fade back
} catch (Exception ex) {
ex.printStackTrace();
if (ex instanceof java.lang.InterruptedException)
return;
}
}
}.execute();
}
});
EDIT: Just to be clear, I'm looking for an efficient way to fade the RGB values for activeButtonColor
back to normalButtonColor
, without having to create a huge number of Color
objects. Is it possible? Or do I just have to limit the number of fade steps to be more efficient?