What is the "better way" to construct the main frame of a GUI: subclass JFrame, or add to it?

Scott Stanchfield

Actually, neither...

I always recommend that you extend JPanel when creating your GUIs.

This allows you to take any GUI and compose a larger GUI that contains it and others. For example, your main window could become a tab in a JTabbedPane later, or be combined in another way. If you extend JFrame, you can never add it to another GUI.

Your "main" application will simply contain code that creates a JFrame, adds your extended JPanel to it, then displays the JFrame.