Results 1 to 6 of 6
  1. #1
    kbro3 is offline Member
    Join Date
    Feb 2011
    Posts
    24
    Rep Power
    0

    Default JButton setEnabled

    Hi all,

    Just wondering, in the context of a JButton, what would setEnabled(false); do?

    I'm looking at someone else's code and they have a setEnabled(false) call inside the button actionlistener, this causes some very weird behaviour, namely apart from normal code, it somehow calls another component's focusgained and focuslost methods.

    Commenting it out makes everything work fine (it would seem). So what's it for?

    Thanks.

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,798
    Rep Power
    7

    Default

    Isn't the name self evident? The methods enables or disables the button. Changes if you can click the button or not.

  3. #3
    kbro3 is offline Member
    Join Date
    Feb 2011
    Posts
    24
    Rep Power
    0

    Default

    So it's just programmatically "unclicking" the button?

  4. #4
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,798
    Rep Power
    7

    Default

    Quote Originally Posted by kbro3 View Post
    it somehow calls another component's focusgained and focuslost methods.
    If the button is disabled then it loses focus. The next component gains focus and obviously fires its FocusListener.

  5. #5
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,798
    Rep Power
    7

    Default

    Quote Originally Posted by kbro3 View Post
    So it's just programmatically "unclicking" the button?
    No, it prevents the user from being able to click the button.

  6. #6
    kbro3 is offline Member
    Join Date
    Feb 2011
    Posts
    24
    Rep Power
    0

Similar Threads

  1. JButton help
    By ThrashingBoy in forum New To Java
    Replies: 8
    Last Post: 03-01-2011, 01:48 AM
  2. JButton help
    By ThrashingBoy in forum New To Java
    Replies: 2
    Last Post: 01-29-2011, 12:39 PM
  3. Problem with button.setEnabled
    By Dycu in forum SWT / JFace
    Replies: 0
    Last Post: 07-19-2010, 12:49 PM
  4. Replies: 4
    Last Post: 02-26-2009, 11:46 PM
  5. Help with JButton
    By geoffreybarwise in forum New To Java
    Replies: 4
    Last Post: 05-21-2008, 10:48 AM

Posting Permissions

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