JButton
押すと、背景色がアクティブから通常に変わります:
final Color activeButtonColor = new Color(159, 188, 191);
final Color normalButtonColor = new Color(47, 55, 56);
特定のタスクの実行が終了したら、アクティブなボタンの色を通常のボタンの色に戻したいです。私は使用しSwingWorker
ていますが、誰かがこれを行うための効率的な方法を提案できるかどうか疑問に思いましたか?
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();
}
});
編集:明確にするために、膨大な数のオブジェクトを作成することなく、RGB 値を にactiveButtonColor
戻す効率的な方法を探しています。出来ますか?それとも、より効率的にするためにフェードステップの数を制限する必要がありますか?normalButtonColor
Color