Home>
contentPane.remove (1);
contentPane.add (new Main (), BorderLayout.CENTER);
revalidate ();


As mentioned above, I was able to redisplay the class called Main (), but the actions in the Main () class no longer work at all.
It didn't work even if I set setEnabled (true);in Action.
KeyEvent also doesn't work.

I have tried the self-solving method.

  • Answer # 1

    In the initial state, the keyboard seems to be out of focus, and I was able to control it by pressing the Tab key.
    It would be nice to have something like focus priority.
    ...
    When I looked it up, it seems that there is a FocusTraversalPolicy, so I set it as follows.

    frame.setFocusTraversalPolicy (new MyFocusTraversalPolicy ());
    Omission
    class MyFocusTraversalPolicy extends LayoutFocusTraversalPolicy {
            @Override
            public Component getDefaultComponent (Container focusCycleRoot) {
            return panel;
            }
    }


    However, there was no change.