내 애니메이션과 JComboBox에 문제가 있습니다. 내 응용 프로그램에서는 마우스와 키보드를 사용하거나 애니메이션을 설정하여 모양을 이동하고 변형 할 수 있습니다.스윙 반복되는 페인트 다시 칠하기 JComboBox 깜박임
내 구성 요소 계층 구조는 다음과 같습니다. JFrame에 배치 된 JPanel에는 EditorCanvas라는 모양의 패널이 포함되어 있으며 모양은 수정되고 그려지며 일부 JButtons 및 JComboBox가 포함 된 DrawMenu라는 패널이 있습니다.
JFrame의 -> 인 JPanel -> EditorCanvas
JFrame의 -> 인 JPanel -> DrawMenu -> JComboBox에
JComboBox가 클릭에 캔버스에 추가 할 모양을 선택하는 데 사용됩니다. 또 다른 스레드에서 새 위치 등을 계산 한 후 매 10ms마다 캔버스에서 repaint()을 호출합니다.
문제는 팝업을 열 자마자 사라질 수 있다는 점입니다. 그리고 이것은 내 repaints에 의해 어느 시점에서 발생합니다. 정말 이상한 점은 내 JComboBox는 다른 패널에 배치되므로 다시 그려서는 안됩니다.
SwingUtilities.invokeLater에서 호출 한 Runnable에서 다시 그리기 호출을 바꾸려고했지만 문제는 그대로였습니다. 여기
내 코드의 몇 가지 관련 부분입니다 :public class EditorCanvas extends JPanel implements MouseListener, MouseMotionListener, KeyListener {
...
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
// To keep keyboard focus
this.requestFocusInWindow();
this.graphics = (Graphics2D) g.create();
this.graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
this.mainRenderer.paintAll(this.graphics);
}
public class AnimationManager implements Runnable {
...
public void run() {
try {
while (Thread.currentThread() == this.thread) {
// Update time values
double curTime = System.currentTimeMillis();
double deltaTime = curTime - this.lastTime;
this.lastTime = curTime;
for (Animation anim : this.animations) {
anim.update(deltaTime);
}
SwingUtilities.invokeLater(new Runnable() {
public @Override void run() {
EditorParameters.getCanvas().repaint();
}
});
// Pause the animation if it has to
synchronized (this) {
while (this.pause) {
System.out.println("\nAnimation paused!\n");
this.wait();
}
}
Thread.sleep(SLEEP_TIME);
}
'repaint' 대신'validate/revalidate/invalidate'을 시도하십시오. 완전한 테스트 가능한 코드를 공유하지 않았기 때문에 작동 여부는 말할 수 없습니다. – Braj