简体   繁体   中英

New JFrame with new thread

I created a JFrame with combo boxes and a button which will create a new thread and continue to do an action. I want a new JFrame to start with every new thread to output logs to the new JFrame. But even if I put the code related to the JFrame in the new thread and close that JFrame it ends the whole program instead of that running thread. What the best approach to making what I want possible? I simply want a new JFrame to open with each new thread started and when I close that JFrame it would end that thread.

Regards!

By default, closing a JFrame will simply hide it (see the documentation for setDefaultCloseOperation() ). If closing a window is exiting your application, this must be due to your own code. You're not, by chance, calling setDefaultCloseOperation(JFrame. EXIT_ON_CLOSE) , are you?

Here are some ideas:

  • Don't block the event dispatch thread; use SwingWorker instead, as shown here .

  • Don't use multiple frames; use panels in a container having a suitable layout .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM