JTable

To start out, we'll create a prototype that introduces the key features of JTable. Then we'll add JTable support to the address application. This time the application will use the MVC architecture—the AddressBook class instance will be a model for the table.

We'll begin by creating a 4-by-4 grid, but first let's learn to use the JTable component. As always, follow along in the interactive interpreter.

Import the JFrame and JTable classes from the javax.swing package.

>>> from javax.swing import JFrame, JTable

Create an instance of JFrame to hold the table.

>>> frame = JFrame('JTable example')

Create an instance of JTable, passing the number of rows and columns to its constructor. Then add the table to the frame.

 >>> table = JTable(4,4) ...

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.