This answer is left here for reference, but this is not the correct answer because it displays inside the EDT stream.
Here's a working fix !: D The main problem is that ComponentResized is not assigned properly until the mouse is released after compression. In addition, since the paint and checkSize methods are synchronized, they can be mutually exclusive in rare cases. The fix is ββto override the validation method in the Frame class. This method is always called if the frame changes state, including contractions and growth. Therefore, we just need to check the size in the validate, and we really can completely forget about using the ComponentResized method in general.
So, here is a working code that compiles as is. I changed some variable names to improve my personal readability.
import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics; import java.awt.Insets; import java.awt.Toolkit; import java.awt.image.BufferStrategy; import java.awt.Frame; public class SmoothResize extends Frame { public static void main(String[] args) { Toolkit.getDefaultToolkit().setDynamicLayout(true); System.setProperty("sun.awt.noerasebackground", "true"); SmoothResize srtest = new SmoothResize();
I hope this works for you!
Besides the last second edit, I changed the logical triple operation to select your shrink or String extension. The last comparison was unnecessary, because for the comparison in question, the values ββmay be greater, less, or equal to each other. There is no other possibility that would not NullPointerException .
Killed text is no longer relevant since I completely deleted this entire method. I indicate other changes that I made to the original post as comments.
source share