Arya
Arya

Reputation: 8965

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!

Upvotes: 1

Views: 2886

Answers (2)

trashgod
trashgod

Reputation: 205765

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.

Upvotes: 4

Ernest Friedman-Hill
Ernest Friedman-Hill

Reputation: 81674

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?

Upvotes: 6

Related Questions