Example usage for javax.swing.table DefaultTableModel insertRow

List of usage examples for javax.swing.table DefaultTableModel insertRow

Introduction

In this page you can find the example usage for javax.swing.table DefaultTableModel insertRow.

Prototype

public void insertRow(int row, Object[] rowData) 

Source Link

Document

Inserts a row at row in the model.

Usage

From source file:SeedGenerator.MainForm.java

private void loadUrlTable() {
    try {/*  w  w  w  .  java2  s  .c o m*/
        PreparedStatement pstmt = con
                .prepareStatement("select url,searchEngine,dateCreated,queryText from form_url_view;");
        // execute the query, and get a java resultset
        ResultSet rs = pstmt.executeQuery();
        ;

        // iterate through the java resultset
        while (rs.next()) {
            String url = rs.getString("url");
            String searchEngine = rs.getString("searchEngine");
            Timestamp time = rs.getTimestamp("dateCreated");
            String queryText = rs.getString("queryText");

            DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");

            Object[] row = { searchEngine, queryText, url, dateFormat.format(time) };
            DefaultTableModel model = (DefaultTableModel) jTable.getModel();
            //model.addRow();
            model.insertRow(0, row);

            //String firstName = rs.getString("url");
        }
        pstmt.close();
        rs.close();
    } catch (Exception e) {
        //System.err.println("Got an exception! ");
        System.err.println(e.getMessage());
    }
}

From source file:SeedGenerator.MainForm.java

protected void processEvent(AWTEvent event) {

    if (!(event instanceof WindowEvent)) {
        if (event instanceof EventSearchWorker) {
            EventSearchWorker ev = (EventSearchWorker) event;
            if (ev.getPercent() > 0) {
                jProgressBar1.setValue(jProgressBar1.getValue() + ev.getPercent());//ev.getPercent());

            } else {
                lblCount4.setText(String.valueOf(++totalUrlCount));
                //txtSeeds.append(ev.getStr());

                DefaultTableModel model = (DefaultTableModel) jTable.getModel();
                //model.addRow();
                model.insertRow(0, ev.getRowValues());

            }//w w  w  . java 2s .c  o m
            if (ev.hasMessage()) {
                lblMessage4.setText(ev.getMessage());
            }
        }

    } else if (event instanceof EventSparqlWorker) {// other events go to the system default process event handler

    } else {
        super.processEvent(event);
    }
}