praks5432
praks5432

Reputation: 7792

Make JTable Display only added Row

Right now I have a JTable using an AbstractTableModel that is using JDBC to access a SQL database. I do this

stmt.executeUpdate(someStr);
fireTableRowsInserted(rowCount,rowCount+1);

This obviously adds the row on the JTable. However, what I'd like to happen is for the JTable to show only the added row.

I thought of maybe creating a result set that contained only the added row, but I can't get that because I don't have an incremental id field.

Is there anything else I could try?

Upvotes: 0

Views: 152

Answers (1)

mKorbel
mKorbel

Reputation: 109813

  1. don't reinvent the wheel, search for ResultsetTableModel, TableFromDatabase (all event are dome on EDT and Swing GUI waiting / freeze untill all events ended, based on AbstractTableModel)

  2. reinvent the wheel,

    a) use Runnable#Thread() or SwingWorker (publish(), progress()) for JDBC

    b) create a proper AbstractTableModel, there are to override proper notifiers,

    c) use the notifiers in the Model, "fireTableRowsInserted(rowCount,rowCount+1);"

    d) all updates to the Swing GUI, JTable, XxxTableModel must be done on EDT

  3. if there are requirents about strictly to override the methods in AbstractTableModel, then look for correct AbstractTableModel, otherwise to use DefaultTableModel and call from Runnable#Thread() or SwingWorker only myModel.addRow(), nothing else

  4. for better help sooner post an SSCCE with data hardcoded into Array instread of JDBC Connections

Upvotes: 1

Related Questions