SORTable - Manual | |||||
Home | Sort Table | Manual | Demo | Other Products |
Quick Start for Visualage
Once you have installed the product (see installation guide here) create a new project and package and make sure that the Virtual Machinery Sorted Table project is visible.
How the SORTable classes work - building a sorted table with 'double-click' sorting
VMTableDemo1 aVMTableDemo1 = new VMTableDemo1(); // ******** Code to initialise table model is here *** com.virtualmachinery.sortedtable.demo.SimpleAccountTableModel aSimpleAccountTableModel = new com.virtualmachinery.sortedtable.demo.SimpleAccountTableModel(); String[][] data = com.virtualmachinery.sortedtable.demo.TableDemoFactory.getSampleData(); aSimpleAccountTableModel.addAllRecords(data); aVMTableDemo1.sortTable.setSortTableModel(aSimpleAccountTableModel ); // ******** End of code to initialise table model *** frame.setContentPane(aVMTableDemo);
How the SORTable classes work - building a sorted table with associated sort button
VMTableDemo aVMTableDemo = new VMTableDemo(); // ******** Code to initialise table model is here *** com.virtualmachinery.sortedtable.demo.SimpleAccountTableModel aSimpleAccountTableModel = new com.virtualmachinery.sortedtable.demo.SimpleAccountTableModel(); String[][] data = com.virtualmachinery.sortedtable.demo.TableDemoFactory.getSampleData(); aSimpleAccountTableModel.addAllRecords(data); aVMTableDemo.sortTable.setSortTableModel(aSimpleAccountTableModel ); // ******** End of code to initialise table model *** frame.setContentPane(aVMTableDemo);
How the SORTable classes work - modifying the presentation of a sorted table
The code below (which is inserted in the main method) illustrates how the appearance of the table can be modified. In this case we are striping the columns painting each alternate one yellow. We are also altering the size of the third column and applying right alignment to the fifth column -
/**** Start of code to change the table to show alternate colours on each column ****/ javax.swing.JTable theTable = aVMTableDemo.sortTable.getScrollPaneTable(); javax.swing.table.DefaultTableCellRenderer aRenderer = new javax.swing.table.DefaultTableCellRenderer(); aRenderer.setBackground(java.awt.Color.yellow); theTable.getColumnModel().getColumn(3).setPreferredWidth(20); int i = 0; while ( i < theTable.getColumnModel().getColumnCount()) { if (i==4) { javax.swing.table.DefaultTableCellRenderer rend2 = new javax.swing.table.DefaultTableCellRenderer(); rend2.setBackground(java.awt.Color.yellow); rend2.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); theTable.getColumnModel().getColumn(i).setCellRenderer(rend2); } else {theTable.getColumnModel().getColumn(i).setCellRenderer(aRenderer);} i+=2; } /**** End of code to change the table to show alternate colours on each column ****/ frame.show();
The table should look something like this -