Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 10 of 10

Thread: frame closing programmatically

  1. #1
    Member
    Join Date
    Mar 2010
    Posts
    111
    Thanks
    19
    Thanked 0 Times in 0 Posts

    Default frame closing programmatically

    I want to close a Frame automatically not by clicking the close button. I want it to be closed programmaticaly.


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: frame closing programmatically

    Either
    frame.dispose();
    or
    frame.setVisible(false);

    The first will actually dispose of the JFrame and all of its components, the second just make it invisible if you ever want to make it visible again during the duration of the program.

  3. #3
    Member
    Join Date
    Mar 2010
    Posts
    111
    Thanks
    19
    Thanked 0 Times in 0 Posts

    Default Re: frame closing programmatically

    but each of them that I use I get the following error;
    "Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException"

  4. #4
    Member Darryl.Burke's Avatar
    Join Date
    Mar 2010
    Location
    Madgaon, Goa, India
    Posts
    494
    Thanks
    8
    Thanked 48 Times in 46 Posts

    Default Re: frame closing programmatically

    Post an SSCCE* or it didn't happen. (link below)
    * SSCCE : Java Glossary

    db

  5. #5
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: frame closing programmatically

    Make sure that the frame you are trying to dispose of exists and is running:

    if (frame != null)
    {
         frame.dispose();
    }

  6. #6
    Member
    Join Date
    Mar 2010
    Posts
    111
    Thanks
    19
    Thanked 0 Times in 0 Posts

    Default Re: frame closing programmatically

    thank you for your point. when I check if the frame is null it returns null but I can see that the frame is open and it is not closed. how is it possible?

  7. #7
    Member Darryl.Burke's Avatar
    Join Date
    Mar 2010
    Location
    Madgaon, Goa, India
    Posts
    494
    Thanks
    8
    Thanked 48 Times in 46 Posts

    Default Re: frame closing programmatically

    So where's that SSCCE?

    db

  8. #8
    Member
    Join Date
    Mar 2010
    Posts
    111
    Thanks
    19
    Thanked 0 Times in 0 Posts

    Default Re: frame closing programmatically

    I am still patient!

  9. #9
    Member Darryl.Burke's Avatar
    Join Date
    Mar 2010
    Location
    Madgaon, Goa, India
    Posts
    494
    Thanks
    8
    Thanked 48 Times in 46 Posts

    Default Re: frame closing programmatically

    Good for you.

    db

  10. #10
    Member
    Join Date
    Mar 2010
    Posts
    111
    Thanks
    19
    Thanked 0 Times in 0 Posts

    Default Re: frame closing programmatically

    good for you that don't have the answer to my question.

Similar Threads

  1. how to set my frame in the middle of the screen
    By chronoz13 in forum AWT / Java Swing
    Replies: 3
    Last Post: February 10th, 2012, 08:13 AM
  2. Replies: 3
    Last Post: April 14th, 2010, 07:33 PM
  3. [SOLVED] frame are exiting at the same time
    By chronoz13 in forum AWT / Java Swing
    Replies: 8
    Last Post: January 25th, 2010, 08:13 PM
  4. how to modify a JList Frame?
    By JM_4ever in forum AWT / Java Swing
    Replies: 0
    Last Post: October 14th, 2009, 11:58 PM
  5. The Frame to be Center Position
    By r12ki in forum AWT / Java Swing
    Replies: 3
    Last Post: October 1st, 2009, 10:36 AM

Tags for this Thread