Home
JoSQL as a TableModelJoSQL as a TableModel
As of version 0.9 JoSQL now contains an implementation of javax.swing.table.TableModel that allows a JoSQL SQL statement to be used with a JTable.
// Create the table.
JoSQLSwingTableModel model = new JoSQLSwingTableModel ();

JTable table = new JTable (model);

model.parse ("SELECT name   Name, " +
                     length Length, " +
                     file   'Is File?'" +
             "FROM   java.io.File" +
             "WHERE  name LIKE '%.java'" +
             "ORDER BY length DESC, name");

model.execute (myFiles);
Simple as that, you can then keep executing the statement with new files (perhaps if you are showing a directory) as many times as you like. But of course you are not just limited to java.io.File objects. The SELECT column aliases provide the column names.

It is also possible to re-order the results dynamically, without modifying the initial SQL (the more usual "mode" of operation):
// Re-order the columns (perhaps in response to a click on the column name).
// Option 1 - using a Map and specifying the columns by index.
SortedMap m = new LinkedHashMap ();

m.put (new Integer (1),
       Query.ORDER_BY_DESC);
m.put (new Integer (2),
       Query.ORDER_BY_ASC);

model.reorder (myFiles,
               m);

// Option 2 - using a textual representation of the ORDER BY clause.
model.reorder (myFiles,
               "ORDER BY name DESC, length ASC");