• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Swing Question

 
Don Wood
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When a user starts the application with a bad parameter, I put up a nice dialog explaing what the problem is. Then I return from my main method (I haven't created any other threads) but the application is still running. There must be a swing thread running somewhere.
In the method that creates and runs the dialog, I have set the dispose flag which is needed to terminate any swing threads created by this dialog.

I could use System.exit() but I would like learn how to fix this. As I add more ui, I don't want to be leaking resources. So what other shutdown calls should be made to terminate Swing properly?
 
Satish Avadhanam
Ranch Hand
Posts: 697
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Don
Originally posted by Don Wood:
When a user starts the application with a bad parameter, I put up a nice dialog explaing what the problem is.

What I was thinking/doing is if the user enters a wrong/invalid paramater then I just printed the message at the command screen only. I thought that would be OK.
Guys, is it OK? Thanks.
 
Don Wood
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Satish,
It probably is OK. I opted for a dialog where I also tell the user what the valid parameters are. OK, that can be done on the command line too but I still need to learn Swing's way of doing things. Swing and I are uneasy partners right now. This dialog has been a nice minimalistic approach to the learning process. If the application would go away, I'd feel better.
 
Satish Avadhanam
Ranch Hand
Posts: 697
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Don Wood:
Hi Satish,
Swing and I are uneasy partners right now.

Awwww. Hey Don, you know what, if you want to apply and learn Swing features in a better way, may be you can design a very good GUI that has many features and you work on that. Moreover if you work on the main window where business(book/search) is done, it will be a bit complicated as there are many other swing components. In that case, you can just let know the valid parameters right on the command screen.
Just my 2c worth
Good Luck.
 
Don Wood
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All in good time, my friend.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think Don is ok. I think it is a nice idea to have a little dialog pop up that helps the user see what are valid entries for the command line. Both options work fine.
Are you thinking that the Dialog will close the application, I think all that will happen is the Dialog will go away, you still have to have to close the App. If you started the RMI Registry in code, then maybe that is what is still up and running and why your app doesn't quit.
I think using System.exit() is a good idea to use.
Mark
 
Stephen Galbraith
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't be afraid to use System.exit(). I think it'll be fine! Swing starts a few threads, which may or may not terminate when you expect them to depending on what you do. So use of System.exit() when you want to leave the app is fine in my opinion.
Steve.
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 12014
220
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Don,
Are you using code like:

Where you have null as the parent frame? If so, a default frame is used, and the thread for that default frame will still be running.
The two solutions I know of are
  • Always specify a frame
    (Even if you just create a dummy frame which is never displayed and is disposed of immediately after use.)
  • (as suggested by Mark & Stephen), force the closure with System.exit()
    I personally don't like this - there is always the possibility that something somewhere will not get the chance to clean up properly.


  • Regards, Andrew
    [ March 19, 2004: Message edited by: Andrew Monkhouse ]
     
    Don Wood
    Ranch Hand
    Posts: 65
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thanks all for the replies.
    Andrew, solution 1 solved the problem nicely. Thanks for the tip.
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic