I'm doing this project for school and for some reason one of by Buttons in one of my Panels has focus(i can change it with the tab button) Well whatever button has the focus is acting weird.
Is there a way that I can have no button have focus? ie. have nothing selected by the tab button?
notice the Rectangle button has a dotted line around it. I want to make that go away.
Thanks!
You can use setFocusable(boolean n) , it´s mainly used to activate or deactivate the focus event (component of the graphical user interface that is selected to receive the input) of the view, both in the tactile / mouse mode, and in the keyboard (cursor) mode.
requestFocus() makes a request that the given Component gets set to a focused state. This method requires that the component is displayable, focusable, visible and have all it's ancestors be visible too.
JTextField is a lightweight component that allows the editing of a single line of text. For information on and examples of using text fields, see How to Use Text Fields in The Java Tutorial. JTextField is intended to be source-compatible with java.
By default, every Frame and Dialog is focusable. Every Window which is not a Frame or Dialog, but whose nearest owning Frame or Dialog is showing on the screen, and which has at least one Component in its focus traversal cycle, is also focusable by default.
button.setFocusable(false);
If you just want it to not show the dotted line, you can also use
button.setFocusPainted(false);
The button will still be focusable, but you won't see the dotted line.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With