JFrame components flickering during window resize operations

I’m working with a custom JFrame that doesn’t have the standard window decorations. This window contains many nested components like JSplitPane elements, various JPanel containers using different layout managers such as GridBagLayout, BoxLayout, and BorderLayout.

The issue I’m facing is weird behavior during resize operations. When I resize the window by dragging from the right edge or bottom edge, everything works smoothly. However, when I try to resize by dragging from the left edge or top edge, all the components inside start flickering and jumping around. This creates a really poor user experience.

I built my own custom resize handler for the JFrame since it’s undecorated. This same resize logic works fine with other windows in my application that have fewer components inside them.

What could be causing this flickering behavior specifically when resizing from the top or left sides? Is there a way to fix this issue? Has anyone encountered similar problems with complex JFrame layouts?

Had this exact problem last year building a custom media player. The flickering happens because you’re updating window position and size at the same time, which causes multiple layout recalculations. Here’s what fixed it for me: when resizing from left/top edges, batch your position and size updates into one operation. Don’t call setBounds() multiple times or set location and size separately. Collect all your coordinate changes first, then apply them once. Order matters too. Update window bounds first, then force a single repaint() call instead of letting components trigger their own repaints. I also disabled automatic revalidation during resize and manually called revalidate() at the end - this cut down the visual artifacts big time. Simple windows don’t have this issue because fewer nested components means fewer layout calculations fighting each other during resize.

double bufferng shld fix this. override paint() in ur main JPanel and use an offscreen image buffer. flicker happens cause components repaints one by one during resize. also, dont call setVisible(false) then setVisible(true) in ur resize code - that causes serious flicker.

Yeah, this is super common with undecorated frames doing complex layouts during resize. The issue happens because resizing from left/top edges means you’re translating coordinates while layout managers are recalculating component positions at the same time. GridBagLayout makes it even worse since it recalculates constraints for every child component. What worked for me was adding a resize preview. Don’t apply size changes immediately during the drag - just collect the resize deltas and apply the final bounds when you release the mouse. Show a lightweight border preview during the drag instead. This stops the constant layout thrashing that’s causing your flicker. Also check if you’re calling validate() or revalidate() too much in your resize handler. These trigger expensive layout passes, and hitting them on every mouse move will definitely cause visual artifacts with complex component trees.

This topic was automatically closed 4 days after the last reply. New replies are no longer allowed.