Вопрос

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?

Это было полезно?

Решение

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.

Другие советы

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();

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top