O'Reilly logo

Java™ Design Patterns: A Tutorial by James W. Cooper

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

Chapter 32. The JTable Class

The JTable class is much like the JList class in that you can very easily program it to do simple things. Similarly, to do more sophisticated things, you can create a class derived from the AbstractTableModel class to hold your data.

A Simple JTable Program

In the simplest program, you can create a rectangular array of objects and use it in the constructor for the JTable. You can also include an array of strings to be used as column labels for the table.

 public class SimpleTable extends JxFrame { public SimpleTable() { super("Simple table"); JPanel jp = new JPanel(); getContentPane().add(jp); Object[] [] musicData = { {"Tschaikovsky", "1812 Overture", new Boolean(true)}, {"Stravinsky", "Le Sacre", new Boolean(true)} ...

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