Results 1 to 5 of 5
  1. #1
    ecliptical is offline Member
    Join Date
    Jan 2010
    Posts
    12
    Rep Power
    0

    Default JButton doesn't disappear when it is supposed to?

    Hi guys, sorry for all of the posting lately but I've been working non stop on my program.

    The problem for this part of my GUI is that when one button is clicked, another is supposed to show up (which works fine). But when that second button is clicked, it is supposed to disappear (which does not work). Here's the coding.

    Java Code:
        panel5 = new JPanel();
        //Panel for getting info on student
        studentNameLabel2 = new JLabel("Student Info is displayed here");
        studentInfo = new JTextArea();
        studentInfo.setColumns(40);
        studentInfo.setLineWrap(true);
        studentInfo.setRows(36);
        studentInfo.setWrapStyleWord(true);
        studentInfo.setEditable(false);
        studentInfoScroll = new JScrollPane(studentInfo);
        studentInfoScroll.createVerticalScrollBar();
        editStuds = new JButton("Edit Students");
        editStuds.addActionListener(this);
        doneStudEdit = new JButton("Done Editing");
        doneStudEdit.setVisible(false);
    
        panel5.add(studentNameLabel2);
        panel5.add(studentInfoScroll);
        panel5.add(studentInfo);
        panel5.add(editStuds);
        panel5.add(doneStudEdit);
    
     public void actionPerformed(ActionEvent e)
      {
     if (e.getSource() == editStuds)
        {
          doneStudEdit.setVisible(true);
          studentInfo.setEditable(true);
          if(e.getSource() == doneStudEdit)
          {
            doneStudEdit.setVisible(false);
            studentInfo.setEditable(false);
          }
        }
    Thanks in advance!
    -Ecliptical

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

  3. #3
    ecliptical is offline Member
    Join Date
    Jan 2010
    Posts
    12
    Rep Power
    0

    Default

    Whoops, problem solved. I forgot to add an action listener to the button. Silly mistake.
    Thanks for the input though Fubarable!

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by ecliptical View Post
    Whoops, problem solved. I forgot to add an action listener to the button. Silly mistake.
    Thanks for the input though Fubarable!
    You're welcome, but it sounds like you need to spend more time debugging and less time posting. :rolleyes:

  5. #5
    ecliptical is offline Member
    Join Date
    Jan 2010
    Posts
    12
    Rep Power
    0

Similar Threads

  1. Drawing disappear!!!!
    By gan5016 in forum Java 2D
    Replies: 7
    Last Post: 09-26-2009, 03:58 AM
  2. Help interpreting what a class is supposed to do
    By bornwithnoname in forum New To Java
    Replies: 2
    Last Post: 11-20-2008, 01:19 AM
  3. How to make a JButton disappear?
    By diab01ical in forum New To Java
    Replies: 2
    Last Post: 06-04-2008, 03:48 AM
  4. Help with JButton
    By geoffreybarwise in forum New To Java
    Replies: 4
    Last Post: 05-21-2008, 11:48 AM
  5. results to code disappear too fast for DOS window
    By dubdubdub in forum New To Java
    Replies: 3
    Last Post: 12-29-2007, 06:07 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
  •