Question

I have an application which consists mainly in a JList being displayed on the screen. I would like that everytime I make a change to the AbstractListModel(adding or removing items to the list) , to somehow notify the app that changes have been made and modify the JFrame's title to something like frame_title[unsaved]. After I would save the app, the [unsaved] tag would go away.

I think maybe using the observer/observable technique would do the job but I am not sure how to do it. Maybe there is something much more appropriate to my problem? I am new to java new to java so that is why I came here asking for help. Thanks.

UPDATE : I can't really use the Observer-pattern in my case because I am already extending the AbstractListModel class.

Was it helpful?

Solution

Use this:

AbstractListModel model = ...;
model.addListDataListener(new ListDataListener() {
    public void intervalAdded(ListDataEvent e) {

    }

    public void intervalRemoved(ListDataEvent e) {

    }

    public void contentsChanged(ListDataEvent e) {

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