Java/Swing: Obtain Window/JFrame from inside a JPanel
You could use SwingUtilities.getWindowAncestor(…) method that will return a Window that you could cast to your top level type. JFrame topFrame = (JFrame) SwingUtilities.getWindowAncestor(this);
You could use SwingUtilities.getWindowAncestor(…) method that will return a Window that you could cast to your top level type. JFrame topFrame = (JFrame) SwingUtilities.getWindowAncestor(this);
To avoid any ambiguity, use the utilities methods from SwingUtilities : SwingUtilities.isLeftMouseButton(MouseEvent anEvent) SwingUtilities.isRightMouseButton(MouseEvent anEvent) SwingUtilities.isMiddleMouseButton(MouseEvent anEvent)