简体   繁体   中英

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?

  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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM