Question

I have a subclass of JPanel, and I want it to, as soon as its parent frame is pack()ed, to set its minimum size to its new preferred size. I've tried using a ComponentAdapter, but JPanels are by default visible; if I setVisible(false) at the beginning of the constructor, the JFrame won't make it visible again. If I use SwingUtilities's method to get the window root, it will return null because it's in a constructor.

Is there a way to do this?

Was it helpful?

Solution

I have a subclass of JPanel, and I want it to, as soon as its parent frame is pack()ed, to set its minimum size to its new preferred size.

If you know the preferred/minimum size before the pack, set it then.

OTHER TIPS

to set its minimum size to its new preferred size

Certainly possible, but whether it is useful ... . You can override the getMininumSize() method to return super.getPreferredSize();

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top