There are 2 direct, different methods for this in SwingUtilities which provide the same functionality (as noted in their Javadoc). They return java.awt.Window but if you added your panel to a JFrame, you can safely cast it to JFrame.