Thursday, April 3, 2008

JTable : Adding Cell Listeners, Getting cell values

Here I intend to show you a sample program which demonstrates how to get the values edited by user in JTable. This is accomplished by using the CellEditorListener Interface. Note the Table Header, Column values, the font type and font size is set custom.This sample program also has the ability to retrieve data from the cell, by mentioning the row and column.

Have a look on these API's that I have used specific for getting the results I just mentioned above
1) javax.swing.event.CellEditorListener

2) javax.swing.event.ChangeEvent
3) javax.swing.table.TableCellEditor

4) javax.swing.table.JTableHeader

Click here to view the code : JTableDemo (2)

Sample screenshots while executing the program

Tuesday, April 1, 2008

JTableDemo : How to add rows to JTable, How to create a JTable by specifying Table Headers and Row Values.

The basic use of JTable is presenting Table, i.e, rows of column centric data to the user.
Here is a program that uses JTable to present such a sample data. Also provision for adding data/rows randomly.
The major Swing API's used for this pupose are
1) javax.swing.JTable
2) javax.swing.table.DefaultTableModel

There are more uses for this swing API, other than just presnting data.

Click Here to view the code

The figure is screenshot when the code mentioned here executes