Results 1 to 4 of 4
  1. #1
    mbschutlz97 is offline Member
    Join Date
    Jan 2014
    Posts
    30
    Rep Power
    0

    Default How do i make a panel go away if a button is clicked?

    What are a couple of examples to code a button that if it's clicked the panel's visibility is set to false? thanks! :)

  2. #2
    pj6444 is offline Senior Member
    Join Date
    Jan 2013
    Posts
    165
    Rep Power
    2

    Default Re: How do i make a panel go away if a button is clicked?

    Java Code:
    public void actionPerformed(ActionEvent e) {
        if(e.getSource() == button) {
            panel.setVisible(false);
        }
    }

  3. #3
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default Re: How do i make a panel go away if a button is clicked?

    Quote Originally Posted by pj6444 View Post
    Java Code:
    public void actionPerformed(ActionEvent e) {
        if(e.getSource() == button) {
            panel.setVisible(false);
        }
    }
    Now he's going to write back that it claims a "symbol not found" compilation error for "button".

  4. #4
    pj6444 is offline Senior Member
    Join Date
    Jan 2013
    Posts
    165
    Rep Power
    2

    Default Re: How do i make a panel go away if a button is clicked?

    Quote Originally Posted by masijade View Post
    Now he's going to write back that it claims a "symbol not found" compilation error for "button".
    That's true. So mb, you need to use this code but also make yourself a JButton button and JPanel panel. You need to make your class implement ActionListener and you must add an ActionListener instance to your JButton.

Similar Threads

  1. Make a website open when a button is clicked.
    By MR bruto in forum New To Java
    Replies: 1
    Last Post: 06-01-2013, 09:42 PM
  2. JFrame freezes when button is clicked
    By JG4m3r in forum AWT / Swing
    Replies: 4
    Last Post: 04-06-2012, 03:20 AM
  3. returning a string when button clicked
    By droidus in forum AWT / Swing
    Replies: 13
    Last Post: 02-02-2012, 03:50 AM
  4. form appear after ok button clicked
    By sks in forum NetBeans
    Replies: 1
    Last Post: 06-01-2011, 08:50 AM
  5. show panel when button clicked
    By Aggror in forum New To Java
    Replies: 6
    Last Post: 10-14-2010, 04:05 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •