Java swing: Remanence when removing a heavy jogl component to add a light component in the same place

In my swing application, when I remove the jLCl GLCanvas from my main component in order to add the jPanel in the same place, there are some display failures: While the old component was removed and before the new one was added, after-images of all pop-ups menus that were previously displayed on top of GLCanvas are visible against the background of the main component.

How can i avoid this?

+4
source share
1 answer

When adding / removing components from the visible GUI, the code should look like this:

panel.remove(...); panel.add(...); panel.revalidate(); panel.repaint(); 

In addition, the code must run in Thread Dispatch Thread . If the code is executed from a listener, it is on the EDT. If the code is running outside the listener, then you probably have to use SwingWorker or SwingUtilities.invokeLater ().

+5
source

Source: https://habr.com/ru/post/1340997/


All Articles