turn off focus border java

‮/:sptth‬/www.lautturi.com
turn off focus border java

To turn off the focus border in Java, you can use the setFocusPainted method of the JComponent class. This method takes a boolean value as an argument, which specifies whether the focus border should be painted or not.

For example, to turn off the focus border for a JButton named myButton, you can use the following code:

myButton.setFocusPainted(false);

Note that this method only affects the focus border of the component. It does not affect the focus behavior of the component.

You can also use the setFocusable method to disable focus for a component. This method takes a boolean value as an argument, which specifies whether the component should be focusable or not. For example:

myButton.setFocusable(false);

This will prevent the button from receiving focus when the user navigates through the user interface using the keyboard.

Keep in mind that disabling focus for a component can affect the usability of your application. It is generally recommended to use focus sparingly and only disable it when necessary.

Created Time:2017-10-17 22:51:24  Author:lautturi