Is it possible to perform active rendering in Java Swing without being on the EDT?

前端 未结 2 1072
生来不讨喜
生来不讨喜 2021-01-19 07:14

I am looking into using Buffer Strategy and the following technique described on the Javadoc:

// Main loop
while (!done) {
 // Prepare for rendering the next         


        
相关标签:
2条回答
  • 2021-01-19 07:24

    In general, no. Painting on a thread other than the event dispatch thread (EDT) results in undesirable artifacts, although the results may be acceptable. This example demonstrates some of the trade-offs. I prefer arranging to draw on the EDT using javax.swing.Timer, but other approaches are possible. Also, your chosen top-level Container may already implement a Buffer Strategy.

    0 讨论(0)
  • 2021-01-19 07:24

    As mentioned by trashdog it is not good idea to do so. Create own animation thread which will draw off-screen image. Then push it to some holder. If paintComponent is called fetch current image and draw it on component. Done. Look at rendezvous pattern.

    0 讨论(0)
提交回复
热议问题