In the short method, I hide the JFrame using setVisible (false). Then I take a screenshot and restore the JFrame with setVisible (true).
After it becomes visible again, the window should display a different image than before (say, part of this screenshot).
The problem is that after calling setVisible (true), the window blinks with the old content for a second of a second before calling paintComponent and an updated state appears.
Perhaps I could get around this ugly, but I wanted to know if there are better solutions.
Thank you in advance for your help.
edit: When preparing the example, I noticed that the effect was practically not observed when I did not use transparency, as in my program. It must have already been mentioned. Here is what I came up with:
import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics; import java.awt.Toolkit; import javax.swing.JFrame; import javax.swing.JPanel; import com.sun.awt.AWTUtilities; public class Test { static boolean flag = false; static Dimension scrSize = Toolkit.getDefaultToolkit().getScreenSize(); public static void main(String[] args) throws InterruptedException { JFrame frame = new JFrame(); frame.setUndecorated(true); AWTUtilities.setWindowOpaque(frame, false);
source share