Panels allow you to organize portions of a larger user interface within a frame, a dialog, or a window. Like frames (java.awt.Frame and javax.swing.JFrame), panels extend the java.awt.Container class, which means that they can contain other components. However, they can't exist on their own but must be in the context of a window, dialog, or frame, or in the context of another panel contained in a top-level window (like Dialog, Frame, or Window).

Here's a JFC/Swing example of adding components with JPanel, in which every time the Add button is pressed another button is added to a panel. Import JPanel and JFrame from the javax.swing package.

>>> from javax.swing import JPanel, JFrame, JButton

Create a frame variable in the global space ...

Get Python Programming with the Java™ Class Libraries: A Tutorial for Building Web and Enterprise Applications with Jython now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.