Sunday, September 24, 2006

JTable Defined

I am going through the beginner Swing tutorial put out by IBM and here is a good description of the JTable:


Think of an Excel spreadsheet when you think of a JTable and that should give you a clear picture of what the JTable does in Swing. It shares many of the same characteristics: cells, rows, columns, moving columns, and hiding columns. The JTable takes the idea of a JList a step further. Instead of displaying data in one column, it displays it in multiple columns. Let's use a person as an example. A JList would only be able to display one property of a person -- his or her name for instance. A JTable, however, would be able to display multiple properties -- a name, an age, an address, etc. The JTable is the Swing component that allows you to provide the most information about your data.

Unfortunately, as a trade-off, it is also notoriously the most difficult Swing component to tackle. Many UI developers have gotten headaches trying to learn every detail of a JTable. I hope to save you from that here, and just get the ball rolling with your JTable knowledge.

Many of the same concepts in JLists extend to JTables as well, including the idea of different selection intervals, for example. But the one-row idea of a JList changes to the cell structure of a JTable. This means you have different ways to make these selections in JTables, as columns, rows, or individual cells.