The setFocusable method of the JButton class in java.awt.event package is used to mark a button as focusable or not focusable. By default, a button is focusable which means it can be selected as a focus component using the tab key.
Code Examples:
1. This code sets a JButton as focusable:
JButton myButton = new JButton("Click me"); myButton.setFocusable(true); // set the button as focusable
2. This code sets a JButton as not focusable:
JButton myButton = new JButton("Click me"); myButton.setFocusable(false); // set the button as not focusable
Brief Explanation:
In Example 1, we create a JButton and set its focusable property to true using the setFocusable method. This button can now be selected as a focus component using the tab key.
In Example 2, we create a JButton and set its focusable property to false using the setFocusable method. This button cannot be selected as a focus component using the tab key.
Package Library:
The setFocusable method is part of the java.awt.event package which is part of the Java AWT (Abstract Window Toolkit) library.
Java JButton.setFocusable - 18 examples found. These are the top rated real world Java examples of java.awt.Event.JButton.setFocusable extracted from open source projects. You can rate examples to help us improve the quality of examples.