Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

setFocusable vs setEnable - when to use what?

843807Dec 8 2009 — edited Dec 9 2009
Dear Experts,

The API:
public void setFocusable(boolean focusable)

    Sets the focusable state of this Component to the specified value. This value overrides the Component's default focusability.
public void setEnabled(boolean enabled)

    Sets whether or not this component is enabled. A component that is enabled may respond to user input, while a component that is not enabled cannot respond to user input. Some components may alter their visual representation when they are disabled in order to provide feedback to the user that they cannot take input.

    Note: Disabling a component does not disable its children.

    Note: Disabling a lightweight component does not prevent it from receiving MouseEvents.
What I understand disabling a JComponent makes it not able to receive focus, and a component which cannot receive focus is unable to respond to user input.

1. Are these two methods basically the same and there is no preference of the usage one over another?
2. Would someone kindly please explain when to use setFocusable and when to use setEnable, if each of the method has special purpose?

Thanks in advance,
Patrick
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 6 2010
Added on Dec 8 2009
9 comments
1,702 views