문제

If I create a custom JPanel (where all of the game I'm making will be displayed on the screen), and override it's paintComponent() for that purpose. Is everything inside that method going to be run on the EDT? And what about other methods inside that same class?

What if I call repaint() on the custom JPanel from inside the run() method of a thread I made? Will paintComponent() still be run on the EDT?

도움이 되었습니까?

해결책

Yes, everything inside that method is going to be run on the EDT including any methods that you invoke within paintComponent().

And what about other methods inside that same class?

If they are called from paintComponent() or from actionPerformed(), etc, then they will also be on the EDT!

What if I call repaint() on the custom JPanel from inside the run() method of a thread I made? Will paintComponent() still be run on the EDT?

repaint() on a non-EDT thread will schedule a repaint -> paintComponent() to be run on the EDT. So yes, still on the EDT! Btw, you can test this by placing a break-point in your paintComponent method and seeing which thread is suspended.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top