When I run my program and I press a key it doesn’t do what it’s supposed to unless I click somewhere on the window to gain focus. I’ve tried using grabKeyboardFocus() and setWantsKeyboardFocus(true) on a bunch of different components but none seem to gain the focus. Is it perhaps grabFocusInternal()? If so can someone explain how to use that function? I’m not sure what to pass in for the first argument. Thank you.
EDIT: Also another thing is I have this code
Now when I run the windows are not visible as I want however when I click it doesn’t appear to gain focus because the F1 and F2 keys do not toggle the visibility of their respective components. What am I doing wrong?