开发者

Java listener on dialog close

I have a Java app that displays a list from a database. Inside the class is the following code to open a new dialog for data entry:

@Action
public void addNewEntry() {
    JFrame mainFrame = ADLog2App.getApplication().getMainFrame();
    addNewDialog = new AddNewView(mainFrame, true);
    addNewDialog.setLocationRelativeTo(mainFrame);
    addNewDialog.addContainerLis开发者_开发百科tener(null);
    ADLog2App.getApplication().show(addNewDialog);
}

How do you add a listener to the main class to detect when the addNewDialog window is closed, so that I can call a refresh method and refresh the list from the database.


If AddNewView is a Window such as a Dialog or JDialog, you could use the Window.addWindowListener(...). That is, in your main class, you do

addNewDialog.addWindowListener(someWindowListener);

where someWindowListener is some WindowListener (for instance a WindowAdapter) which overrides / implemetnns windowClosed.

A more complete example, using an anonymous class, could look like

addNewDialog.addWindowListener(new WindowAdapter() {
    @Override
    public void windowClosed(WindowEvent e) {
        refreshMainView();
    }
});

Relevant links:

  • Official Tutorial: How to Write Window Listeners


you have to add WindowListener and override windowClosing Event, if event occured then just returs some flag, example here

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜