JFrame UI elements flicker during window resize operations

I’m working with a custom borderless JFrame that contains many nested UI elements like JSplitPane, JPanel components using various layout managers including GridBagLayout, BoxLayout, and BorderLayout. The window building code is quite extensive at around 2500 lines.

The issue I’m facing is with resize behavior. When I resize the window by dragging the right or bottom edges, everything works smoothly. However, when I try to resize by dragging the left or top edges, all the UI components start flickering badly, creating a very poor visual experience.

What I want to know: What causes this flickering behavior? Is there a way to fix this issue? Has anyone encountered and solved this problem before?

Additional info: I created a custom resize handler for the JFrame. This handler works fine with other windows that have fewer UI components.

yeah, it’s likely a double buffering issue. try enabling setDoubleBuffered(true) on your main panels. also, check your resize handler; it might trigger too many repaints when resizing from the left or top. complex layouts can definitely cause this flicker.

This flickering happens because resizing from left/top edges forces your custom resize handler to recalculate and reposition everything, not just stretch it like right/bottom resizing does. With 2500 lines of UI code and nested components, each repaint gets expensive. I hit the same issue with a complex trading app. The fix? Override your JFrame’s validate() method to batch layout updates, and only call repaint() once after all resize calculations finish - not during the intermediate steps. Also try SwingUtilities.invokeLater() to defer repaints until the resize operation’s done. Completely eliminated the flickering for me.

that flicker’s probably from your borderless frame setup. when you drag the left/top edges, windows keeps firing resize events and your handler redraws everything constantly. override paint() to cache component states while dragging, then only repaint when you stop. fixed the same issue in my media player.

Had the same flickering issue when I built a document editor with nested panels. The problem is left/top resizing changes both position and size for all components at once, while right/bottom only changes dimensions. Your custom resize handler is probably calling setBounds() multiple times during the drag, so you’re painting invalid intermediate states. Here’s what fixed it for me: override JComponent.isOptimizedDrawingEnabled() to return false on your main container - this stops automatic repainting during resize. Then manually control when repaints happen. Also try wrapping your resize logic in EventQueue.invokeLater() so the resize finishes before any painting starts. Complex layouts like GridBagLayout make this worse since position calculations keep running during the drag.

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