JTableView

JavaTools contains functions that allow the user to
- view tabular data in a Java Swing JTable-formatted format in the Mathematica front-end
- edit tabular data in a Java Swing JTable, and assign to a symbol, with strict type checking

These functions are similar to the TableView[] symbol in Mathematica, but it allows the user to edit the data and assign to a symbol. TableView[] in Mathematica, which is still an experimental and therefore undocumented feature, allows the user to edit the data, but then it cannot be assigned to a symbol for further processing.

In its simplest form, JTableView[] just outputs the data of the matrix, without column headers.

In[37]:=

"jtableview_1.gif"

Out[37]=

"jtableview_2.gif"

Rational data is automatically converted to Real so it can be displayed in the Java JTable.

Column headers are optional.

In[54]:=

"jtableview_3.gif"

Out[54]=

"jtableview_4.gif"

In[57]:=

"jtableview_5.gif"

Out[57]=

"jtableview_6.gif"

The data and the colum headers can be of any type. However, the types of the first data row determine the types that are permitted for the whole column. Reals are permitted when the first line contains an integer, as they can be cast to real, but not vice versa. Reals and integers are permitted when the first line contains a string, as both can be displayed as string. The converse is not true.

In[43]:=

"jtableview_7.gif"

Out[43]=

"jtableview_8.gif"


JTableViewEdit[]
can be used to create a new Java window to edit the data. It should be assigned to a symbol, or the changes are lost.

In the selected row, one can tab from column to column. If the user attempts to enter data of invalid type for the selected column, it will block the data entry and show the cell in a red frame.

The input

"jtableview_9.gif"

creates a new JTable window

"jtableview_10.gif"

Here we select a row for editing

"jtableview_11.gif"

We attempt to enter a number of invalid type for column 3. Before pressing Return ...

"jtableview_12.gif"

... and after pressing Return. The data of wrong type is not accepted. This is to prevent erroneous manul input, which type checking can catch.

"jtableview_13.gif"

We correct the 77.89 to the integer 77, and the number is accepted.

Once we close the window, we get the data in the Mathematica front-end.

In[46]:=

"jtableview_14.gif"

Out[46]=

"jtableview_15.gif"

The columns can be dragged with the mouse.

In[48]:=

"jtableview_16.gif"

"jtableview_17.gif"

"jtableview_18.gif"

"jtableview_19.gif"

It is possible to specify RGB color differences for the alternating colors of the lines.

In[51]:=

"jtableview_20.gif"

"jtableview_21.gif"

JTableViewEdit[] can be used without providing any initial data. In that case the list of valid data types has to be specified explicitly. JTableViewEdit[] will then initialize the table with default values: 0 for Integer, 0.0 for Real, and "" for String.

"jtableview_22.gif"

"jtableview_23.gif"

If no list of types is provided, JTableViewEdit[] assumes that all data is of type Real and initialize with 0.0 for the whole table.

In[53]:=

"jtableview_24.gif"

"jtableview_25.gif"

"jtableview_26.gif"

Applications

Retrieve data from a database and display.

In[88]:=

"jtableview_27.gif"

In[89]:=

"jtableview_28.gif"

In[90]:=

"jtableview_29.gif"

Out[90]=

"jtableview_30.gif"

In[96]:=

"jtableview_31.gif"

Out[97]=

"jtableview_32.gif"

Retrieve data from a database and edit and save. Data of invalid column type is not accepted.

In[98]:=

"jtableview_33.gif"

"jtableview_34.gif"

"jtableview_35.gif"

"jtableview_36.gif"

"jtableview_37.gif"

"jtableview_38.gif"

"jtableview_39.gif"

Upon closing the window and displaying newroyaltyschedule:

In[83]:=

"jtableview_40.gif"

Out[83]=

"jtableview_41.gif"

In[87]:=

"jtableview_42.gif"

Spikey Created with Wolfram Mathematica 7.0