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 2 of 2

Thread: Help with closing a JFrame (not the program)

  1. #1
    Junior Member
    Join Date
    Feb 2012
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Help with closing a JFrame (not the program)

    so i'm trying to create a JButton that closes the JFrame that it is in. here is the button code


    JButton buttonClose = new JButton("Close");
    buttonClose.setVisible(true);
    panelHelp.add(buttonClose);
    buttonClose.dispose();

    Im getting this error:
    the method dispose(); cannot be defined. I'm assuming I need to put an arg in but don't know what needs to go there. I'm new to Java so please go easy on me.

    I tried to add an actionlistener as well and that didn't work either.


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

    Default Re: Help with closing a JFrame (not the program)

    The API does not define a dispose() method for a JButton
    http://docs.oracle.com/javase/6/docs...ng/JButton.htm
    If you wish to dispose of the parent JFrame, call dispose on the JFrame (for which the API defines a dispose method: JFrame (Java Platform SE 6) ).

    I tried to add an actionlistener as well and that didn't work either.
    We cannot comment on code that we cannot see, and cannot comment on why it didn't work without an explanation of 'didn't work' means.

Similar Threads

  1. help with JButton closing a JFrame :)
    By skerridge in forum AWT / Java Swing
    Replies: 15
    Last Post: January 16th, 2012, 12:11 AM
  2. JOption to JFrame HELP...messed my program up
    By scottgilliland2003 in forum What's Wrong With My Code?
    Replies: 9
    Last Post: December 20th, 2011, 07:18 PM
  3. Need help correcting a JFrame program for class!
    By AlexAndAHalf in forum What's Wrong With My Code?
    Replies: 9
    Last Post: November 23rd, 2011, 03:03 AM
  4. Help with JFrame program that calculates average
    By ePerKar3 in forum AWT / Java Swing
    Replies: 3
    Last Post: November 4th, 2011, 08:48 AM
  5. How to allow my program to keep runningwithout closing it?
    By esplanade56 in forum Java Theory & Questions
    Replies: 3
    Last Post: July 18th, 2011, 06:11 AM