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

Get Java™ Design Patterns: A Tutorial 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.