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?
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:
If you really have to:
int state = frame.getExtendedState();
frame.pack();
frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
... Otherwise @mre's solution is (much) better! :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With