Creating a Simple Table

This demonstration is based on the Swing simple table demo in the Java Tutorials - how to use tables. The code for E-Gantt has been changed slightly to indicate the differences in the API between E-Gantt and the standard JTable (no graphics just yet).

JTable example

This JTable example shows the simplest usage of the JTable by using static columns and values passed in via the contructor.

Using this method the JTable will automatically generate the appropriate Column Models and Choose the renderer based on the column values.
TableDemo.gif

JTable Example code

String[] columnNames = {"First Name",
"Last Name",
"Sport",
"# of Years",
"Vegetarian"};
 
Object[][] data = {
{"Mary", "Campione",
"Snowboarding", new Integer(5), new Boolean(false)},
{"Alison", "Huml",
"Rowing", new Integer(3), new Boolean(true)},
{"Kathy", "Walrath",
"Knitting", new Integer(2), new Boolean(false)},
{"Sharon", "Zakhour",
"Speed reading", new Integer(20), new Boolean(true)},
{"Philip", "Milne",
"Pool", new Integer(10), new Boolean(false)}
};
 
JTable table = new JTable(data, columnNames);

E-Gantt Example

The E-Gantt example shows the usage of two tables instead of one sitting inside of a split pane as you can note the changes between the two code example are very minor:
  • The column array has been specified as as [][] to allow the specification of multiple column models one for each side of the table.
  • The class to instantiate has been changed from JTable to GanttTable

SimpleTableExample.jpg

E-GANTT Example Code

String[][] columnNames = {
{"First Name", "Last Name", "Sport", "# of Years"},
{ "Vegetarian"}};
// Data works the same with E-Gantt
Object[][] data = {
{"Mary", "Campione",
"Snowboarding", new Integer(5), new Boolean(false)},
{"Alison", "Huml",
"Rowing", new Integer(3), new Boolean(true)},
{"Kathy", "Walrath",
"Knitting", new Integer(2), new Boolean(false)},
{"Sharon", "Zakhour",
"Speed reading", new Integer(20), new Boolean(true)},
{"Philip", "Milne",
"Pool", new Integer(10), new Boolean(false)}
};
final GanttTable table = new GanttTable(data, columnNames);

Multiple Tables

The first difference you will notice when you use E-Gantt is that instead of one table we use two. The only code difference is in the contruction of the columns both tables use the same table model however they required different column models.

This is achieved in the constructor by passing instead of singular string array String [columnNumber] for columns we use the double array syntax String [columnModelIndex][columnNumber]

Gantt Table

The second and final difference for this example is that we no longer instantiate the JTable but the GanttTable. The GanttTable encapsulate as much logic as possible to do with the usage of two tables and a convienience .

The code example for this demo can be found

Custom Table Model

Like the JTable the E-Gantt API will also all the user to specify the table model this will allow you to do functionality such as:
  • Sorting by Column
  • Custom Tooltips
  • Dynamic Table models
Some of these examples are covered with-in the E-Gantt table tutorials, based on the Swing examples if you have not gone through the Swing tutorials for JTable I suggest you to do so. This will make your experience with the E-Gantt library a lot easier as a lot of effort has gone in to prevent this library from re-inventing the wheel

external image sflogo.php?group_id=49356

.