I have a control that should react to some kinds of events, and therefore adds itself to a listener list in the constructor. Of course it should remove itself as well, but while Swing and RCP have dispose()
methods, I can't seem to find any in JavaFx.
public class MyTable extends TableView implements MyListener {
public MyTable () {
Events.addListener(this);
}
public disposeOrSomething() {
Events.removeListener(this);
}
// actual implementation of MyListener
}
Don't get hung up on the static Events
class, thought. It does not matter to me if the control adds itself to something static or not. What is important: there are two parts of an application that are not connected except for a general event system. So when the listening part vanishes (e.g. the window gets closed) of course the listener should be disposed.
Up until know, when the listener was directly connected to the life cycle of the control, the control registered it. But now in JavaFX that won't work, and due to loosely coupled FXML files I can't see anyone else who has the necessary information (the control and the "window close event") either.
So what is a good way to clean up after controls when they are no longer used?