1

I'm trying to switch into windows and "closing" the last window. But, I want to have a shortcut (Ctrl+I) to open a new window, and if I put the setVisible(false) at the ActionPerformed of the (Ctrl+I), it gives me an error.

How can I hide the last window?

Error says:

create method setVisible(boolean) in 
    <anonymous javax.swing.AbstractAction>

Here's the code:

jBNew.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_I, InputEvent.CTRL_DOWN_MASK), "new");
jBNew.getActionMap().put("new", new AbstractAction() {
    @Override
    public void actionPerformed(ActionEvent e) {
      this.setVisible(false);(here i have the error)****
        new NextOrderWindow(codLastOrder()).setVisible(true);
    }
});
Community
  • 1
  • 1
  • 4
    Why would an `AbstractAction` be *visible*? If you want to hide the "last window", then you need a reference to the "last window". – Elliott Frisch Jun 25 '18 at 23:51
  • 3
    `this` is referencing the (anonymous) instance of `AbstractAction`, which obviously, doesn't have a `setVisible` method – MadProgrammer Jun 25 '18 at 23:54
  • 1) For better help sooner, post a [MCVE] or [Short, Self Contained, Correct Example](http://www.sscce.org/). 2) See [The Use of Multiple JFrames, Good/Bad Practice?](http://stackoverflow.com/q/9554636/418556) – Andrew Thompson Jun 26 '18 at 00:16

0 Answers0