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

Thread: Problem with java swing JButton in Netbeans IDE

  1. #1
    Junior Member
    Join Date
    Dec 2010
    Location
    Madurai
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Problem with java swing JButton in Netbeans IDE

    Hi friends,

    I have created new GUI project in Netbeans and i placed a JButton. I have also add the Event handling by JButton(right click)-->events-->mouse-->mouse clicked. I just print "hello" when the button is clicked and disable the button by setting his property.
     
            private void jButton1MousePressed(java.awt.event.MouseEvent evt) {                                        
            // TODO add your handling code here:
            jButton1.setEnabled(false); //(or)jButton1.setSelected(true);
            System.out.println("hello");
        }

    Now i have a strange problem. Once the button is clicked, it becomes disabled and hello is printed and next time when i click the disabled button , that time also the event handling procedure is called and hello is printed again. But i don't want to print hello when clicking disabled button.

    What to do? Where i have made the mistake??

    with regards,
    Raja Pandi


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

    Default Re: Problem with java swing JButton in Netbeans IDE

    Remove the mouse listener, or add a conditional in the listener method that checks if the button is enabled.

  3. The Following User Says Thank You to copeg For This Useful Post:

    vrp (January 13th, 2011)

  4. #3
    Junior Member
    Join Date
    Dec 2010
    Location
    Madurai
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Problem with java swing JButton in Netbeans IDE

    Quote Originally Posted by copeg View Post
    Remove the mouse listener, or add a conditional in the listener method that checks if the button is enabled.
    Oh, then the mouse listener will be called even though the button is disabled?? If it so, i go by adding a conditional there. Thank you friend. :-)

    with regards,
    Raja Pandi

Similar Threads

  1. How to Add ActionListener to a JButton in Swing?
    By JavaPF in forum Java Swing Tutorials
    Replies: 17
    Last Post: April 24th, 2013, 05:14 PM
  2. Netbeans Swing Design
    By kurt-hardy in forum AWT / Java Swing
    Replies: 7
    Last Post: December 6th, 2010, 11:38 AM
  3. netbeans JTable Jbutton
    By Mr.President in forum AWT / Java Swing
    Replies: 6
    Last Post: July 19th, 2010, 08:37 AM
  4. [SOLVED] Java Swing problem?
    By nasser in forum AWT / Java Swing
    Replies: 2
    Last Post: July 3rd, 2010, 12:34 PM
  5. JAVA Image Icon and JButton resizing problem
    By antitru5t in forum AWT / Java Swing
    Replies: 1
    Last Post: March 13th, 2009, 04:39 AM

Tags for this Thread