• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Closing a JFrame

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Probably a very obvious answer to this one, but I can't find it.

I want to close a JFrame during the running of a program without killing the object that created it. I have looked for a frame.close() or frame.exit() method, but they don't seem to exist.

Is there an easy way of doing this?
 
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
if you want to hide the JFrame use setVisible(false) if you want to remove the JFrame and release its resources use dispose()
 
Guy Shahar
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Nick

This works and the frame disappears. Does it really free all the resources of the frame?

I ask because when I clicked for the frame to be recreated, it appeared in the same place on the screen as it had been when I clicked for it to be closed. (or maybe this was within the memory of the object??)

Thanks

Guy
 
Nick Meverden
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Releases all of the native screen resources used by this Window, its subcomponents, and all of its owned children. That is, the resources for these Components will be destroyed, any memory they consume will be returned to the OS, and they will be marked as undisplayable.

The Window and its subcomponents can be made displayable again by rebuilding the native resources with a subsequent call to pack or show. The states of the recreated Window and its subcomponents will be identical to the states of these objects at the point where the Window was disposed (not accounting for additional modifications between those actions).
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's good info Nick. Unfortunately, you didn't state where you got that information. So I'll do it for you.

Java API - Window class

Guy, the API is a wonderful and invaluable tool for us Java developers. Be sure and bookmark it. It can save you a ton of time once you learn how to use it.
 
Guy Shahar
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Gregg

Yes, I know about the API - my only problem is that when there is something I want to do, it is not always obvious where in the API I need to look to find it....
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Guy Shahar:
Thanks Gregg

Yes, I know about the API - my only problem is that when there is something I want to do, it is not always obvious where in the API I need to look to find it....



I totally agree. Starting with the method you don't understand in the class that contains said method is usually a good start. The API takes a bit of getting used to. I often find myself in moments because I forgot about the API.
reply
    Bookmark Topic Watch Topic
  • New Topic