gotch4 gotch4 - 6 months ago 49
Java Question

Java Swing pack() on a Window un-maximizes it, how to avoid that?

I've a window and since I dinamically change it's children (sometimes I swap JPanels), I found no other solution than calling pack() on the window to get the new element displayed. Otherwise it will show up only if I resize manually the window.

The problem with this is that the if the window is maximized, after pack() it won't be anymore, which is not what I could give to the client.

Any clues?

mre mre

First of all, I hope that you're using CardLayout for panel swapping, since this functionality is built into that particular layout manager. And typically, you'll want to invoke validate/revalidate and repaint on the container to refresh the display.

See also: