Problem - cannot display rows correctly in jTable

Discussion in 'Java' started by dtsignopoulos@gmail.com, Nov 27, 2006.

  1. Guest

    There seems to be a problem with processing and inserting large (>2000)
    amounts of data into jtable.

    I read single rows from a database, do some processing and use
    insertrow() to feed them to jtable. They get to be displayed (UI) as
    soon ALL rows are done and over with, whereas the desired functionality
    is to be displayed as soon as they are entered (row by row).

    Need help as this is turning up to take too much time to figure out.
    Have tried several approaches with no luck.

    Some code is listed below:

    // Create staff
    DefaultTableModel model_matrix = new DefaultTableModel();
    JScrollPane jScrollPane_matrix = new JScrollPane();
    JTable jTable_matrix = new JTable(model_matrix) {
    public boolean isCellEditable(int rowIndex, int vColIndex) {
    return false;
    }

    // Add some columns
    model_matrix.addColumn("Timestamp");
    model_matrix.addColumn("hpic");

    //Insert rows
    while (more db rows...){
    read row...
    process row...
    //insert row
    i = model_matrix.getRowCount();
    model_matrix.insertRow(i, new Object[] {timestamp, HPIC});
    model_matrix.fireTableRowsInserted(i,i); setSelectedRow(i);

    }

    Need help, thanxs
    , Nov 27, 2006
    #1
    1. Advertising

  2. wrote:
    >
    > I read single rows from a database, do some processing and use
    > insertrow() to feed them to jtable. They get to be displayed (UI) as
    > soon ALL rows are done and over with, whereas the desired functionality
    > is to be displayed as soon as they are entered (row by row).


    If you are running your database code in the Event Dispatch Thread (EDT)
    then repaints (and the like) will not get a chance to run. If you run
    your table update code outside of the EDT, then you will run into
    trouble. Therefore, access the database in another thread and pass the
    data over to the EDT. Use EventQueue.invokeLater - Google will probably
    come up with more information.

    > model_matrix.insertRow(i, new Object[] {timestamp, HPIC});
    > model_matrix.fireTableRowsInserted(i,i); setSelectedRow(i);


    DefaultTableModel.insertRow should fire the row insert event. Sending
    two events imply that two rows were inserted.

    Tom Hawtin
    Thomas Hawtin, Nov 27, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Tivo Escobar
    Replies:
    1
    Views:
    7,314
    manusa
    Apr 12, 2007
  2. Replies:
    0
    Views:
    433
  3. Tintin92
    Replies:
    1
    Views:
    1,697
    Andrew Thompson
    Feb 14, 2007
  4. cp
    Replies:
    3
    Views:
    206
    Jason
    Dec 24, 2004
  5. Haircuts Are Important
    Replies:
    3
    Views:
    318
    Haircuts Are Important
    Jun 4, 2013
Loading...

Share This Page