나는, 누르면, 정상 활동에서 배경색을 변경하는 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();
}
});
편집 : 그냥 명확하게하기 위해, 내가 Color
대량의 객체를 생성하지 않고, 다시 normalButtonColor
-activeButtonColor
의 RGB 값을 퇴색 할 수있는 효율적인 방법을 찾고 있어요. 가능한가? 아니면 더 효과적 이도록 페이드 단계의 수를 제한해야합니까?
물론 그렇습니다.하지만 페이드가있는 동안 매번 여러 Color 객체를 만드는 것을 피하는 방법은 무엇입니까? 여기에 뭔가 빠져있을 수도 있지만 Color는 변경되지 않는 것으로 보입니다. 내가 추측하고있는 색의 rgb 값을 변경해야합니다. – Jon
중간 색상 개체의 배열을 만들고 클래스 수준에서 유지 하시겠습니까? –