O'Reilly logo

Python Programming with the Java™ Class Libraries: A Tutorial for Building Web and Enterprise Applications with Jython by Richard Hightower

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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) ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required