JTable update – upward^downward (editingStopped()

Upward — update table Model from SQL, MOM (mkt data), or timer (overwhelming mkt data), then fire events.
Downward — mouse/keyb — user editing a cell, then propagate to DB or other UI components.
(–> Here you see the threading issue.)

Q1: How many ways are there to read/write data in jtable?
%%A: i guess 1 — via the table model.

Q1b: is there a separate copy of the model data in the JTable instance?
%%A: i don’t think so.
A: My tests confirm that user edits directly hit the underlying table model (eg 2D array). See also P 449 [[java cookbook]].

   /** Invoked on EDT, when editing is finished.
     * @param  e  the event received
JTable.editingStopped(ChangeEvent e) invokes on EDT —

JTable.getModel.setValueAt(). This method should be customized in your own table model. Your setValueAt() should modify your own data structure (2D array etc) and then fire events
     public void setValueAt(Object value, int row, int col) {
        data[row][col] = …

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s