I have a panel being changed by an action which swaps out it’s child panel with a new panel that has a different minimum Size. I need to inform my JSplitPane that one of it’s children panels has changed so I can call updateToPreferedSize method. Is there an event that is already fired which I should listen for? If not, how do I throw an event that the parent can catch to notify it?
I have a panel being changed by an action which swaps out it’s child
Share
The easiest way would be to fire a custom propertyChange event on the panel that swaps out the child, so that after it swaps out the child, it fires the event. Theres a good example here:
http://download.oracle.com/javase/tutorial/javabeans/properties/bound.html
Once you’ve done that, the JSplitpane can register a listener and listen for that property as described here:
http://download.oracle.com/javase/tutorial/uiswing/events/propertychangelistener.html
To sum it up, in the panel that swaps the child, you will need to initialize PropertyChangeSupport:
Then when you swap out the panel:
And in the JSplitPane, you need something like this: