0

I am using HSQL in memory database in my java application. I am opening the GUI manager provided by the HSQLDB by invoking main method of DatabaseManagerSwing class. It opened successfully.

I need to register a callback or notified when the user closes the window manually. I am not able to find anything similar in the docs and after seeing the code of DatabaseManagerSwing class, I think it is not supported.

The stop method simply clear its variables and does not call any other method. As I was thinking if it supports this, it must store the callback objects somewhere and finally call them in stop method. But unfortunately, nothing.

Is there any way or a workaround to get this done ? I need to perform some action when user closes the window.

RamPrakash
  • 1,687
  • 3
  • 20
  • 25
Aman jangra
  • 268
  • 1
  • 16
  • See [this answer](https://stackoverflow.com/a/5401319/418556) (which implements a `SecurityManager`). – Andrew Thompson Dec 23 '19 at 14:14
  • Actually the swing code is libraries'. I can't control it. Maybe, it is not a swing problem but a question related to library itself. As to, is there something in the hsqldb API that can make it possible. I think I am right, but in case it is somehow possible, please elaborate a little as I not able to grasp it. – Aman jangra Dec 23 '19 at 14:43

1 Answers1

0

I added a shutdownhook so that, it runs when the program terminates. But that's not it. Make sure while starting the HSQL Database Manager, do not pass the --noexit argument. By not passing the argument, JVM will exit when you close the Database Manager window.

By adding this

Runtime.getRuntime().addShutdownHook(new Thread(() -> {
        // do your stuff
    }) {
    });

You can do what you want to do when the window is manually closed by the user.

Aman jangra
  • 268
  • 1
  • 16