JPanel

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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.