In inner classes, you will need to add using this with the class name of the outer class if you need to get a reference to the outer class: for example, use
MyWindow.this.setUndecorated(...)`
As an aside, you really don't want to extend the JFrame here and in most situations.
In addition, the ancestor window that contains the JButton can be obtained in other ways, for example, through SwingUtilities.getWindowAncestor(theButton) . i.e.,
public void actionPerformed(ActionEvent e) { Object source = e.getSource(); if (source instanceof JButton) { JButton button = (button) source; Window ancestorWin = SwingUtilities.getAncestorWindow(button); ancestorWin.setUndecorated(!isFullScreen); ancestorWin.setResizable(isFullScreen);
Or, if you know for sure that the ancestor window is a JFrame:
public void actionPerformed(ActionEvent e) { Object source = e.getSource(); if (source instanceof JButton) { JButton button = (button) source; JFrame ancestorWin = (JFrame) SwingUtilities.getAncestorWindow(button); ancestorWin.setUndecorated(!isFullScreen); ancestorWin.setResizable(isFullScreen);
source share