Java listener on dialog close

前端 未结 2 1044
萌比男神i
萌比男神i 2020-12-31 01:01

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 addNe         


        
相关标签:
2条回答
  • 2020-12-31 01:30

    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
    0 讨论(0)
  • 2020-12-31 01:33

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

    0 讨论(0)
提交回复
热议问题