Example usage for javax.swing.table DefaultTableModel removeRow

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

Introduction

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

Prototype

public void removeRow(int row) 

Source Link

Document

Removes the row at row from the model.

Usage

From source file:Records.Database.LibraryUpdater.java

/**
 * Delete file.//from  w w w  .j ava 2 s.  co m
 */
private static void deleteFile() {
    System.out.println("LibraryUpdater.deleteFile()");

    DefaultTableModel model = (DefaultTableModel) RecordsMain.getUI().getUserLibrary().getModel();
    String ID = null;
    for (int x = 0; x < paths.size(); x++) {
        try (ResultSet Result = RecordsMain.dba.getIDByPath(paths.get(x).toString())) {
            if (Result.next()) {
                ID = Result.getString("Song_ID");
                ResultSet results = RecordsMain.dba.SearchLibByID(ID);
                try {
                    // While there are more results to process
                    if (results.next()) {
                        String title = results.getString("SONG_TITLE");
                        String artist = results.getString("ARTIST");
                        String album = results.getString("ALBUM");
                        String genre = results.getString("GENRE");

                        for (int y = 0; y < model.getRowCount(); y++) {
                            if (model.getValueAt(y, 0).equals(title) && model.getValueAt(y, 1).equals(artist)
                                    && model.getValueAt(y, 2).equals(album)
                                    && model.getValueAt(y, 3).equals(genre)) {
                                // System.out.println("Removing Row!");
                                model.removeRow(y);
                                RecordsMain.dba.deleteByID("LibSongs", ID);
                                RecordsMain.dba.deleteByID("LibAlbums", ID);
                                RecordsMain.dba.deleteByID("LibArtists", ID);
                                RecordsMain.dba.deleteByID("LibFilePaths", ID);
                            }
                        }
                        RecordsMain.getUI().NumSongs.setText("" + model.getRowCount() + " Songs");
                    }
                    results.close();

                } catch (SQLException ex) {
                    Logger.getLogger(LibraryUpdater.class.getName()).log(Level.SEVERE, null, ex);
                }
                RecordsMain.clearFilePathList();
                ResultSet res = RecordsMain.dba.getAllFilePaths();
                try {
                    while (res.next()) {
                        String fPath = res.getString("Filepath");
                        RecordsMain.addToFilePathList(fPath);

                    }
                } catch (SQLException ex) {
                    Logger.getLogger(DBSQL.class.getName()).log(Level.SEVERE, null, ex);
                }

            }
        } catch (SQLException ex) {
            Logger.getLogger(LibraryUpdater.class.getName()).log(Level.SEVERE, null, ex);
        }

    }
}

From source file:sk.stuba.fiit.kvasnicka.topologyvisual.gui.simulation.SimulationTopComponent.java

private void loadRules(DefaultTableModel model, List<Data> dataList) {
    //delete all old simulation rules
    while (model.getRowCount() != 0) {
        model.removeRow(0);
    }// ww  w  .  j  a v a 2 s .  c o m

    //add new simulation rules
    for (Data rule : dataList) {
        model.addRow(new Object[] { rule.getId(), rule.getName(), rule.getSourceVertex().getName(),
                rule.getDestinationVertex().getName(), rule.isPing() });
    }
}

From source file:thesis.Ontology_System.java

public void populate_search() {
    DefaultTableModel model = (DefaultTableModel) ad_table.getModel();
    // table_overview.getColumnModel().getColumn(1).setCellRenderer(new TableCellLongTextRenderer ());
    ad_table.getTableHeader().setFont(new java.awt.Font("Segoe UI", Font.BOLD, 14));
    ad_table.getTableHeader().setBackground(Color.WHITE);
    ad_table.setShowGrid(true);// w  w w. j  av  a2s . c o m

    String searched = jTextField1.getText();
    searched = "%" + searched + "%";

    String category = (String) jComboBox1.getSelectedItem();

    switch (category) {

    case "Ad/Product": {
        category = "ad_name";
        break;
    }
    case "Brand": {
        category = "brand";
        break;
    }
    case "Model": {
        category = "model";
        break;
    }
    case "Site": {
        category = "site";
        break;
    }
    }

    for (int row_index = ad_table.getRowCount(); ad_table.getRowCount() != 0; row_index--) {
        if (row_index == 0) {
            JOptionPane.showMessageDialog(null, "last");
        }
        model.removeRow(row_index - 1);
    }

    try {
        sql = "SELECT * FROM `ontology_system_final_table` WHERE `" + category + "` LIKE '" + searched + "' ";
        pst = getConnectiontoDB().prepareStatement(sql);
        rs = pst.executeQuery();

        while (rs.next()) {

            model.addRow(new Object[] { rs.getString("ad_name"), rs.getString("site"), rs.getString("brand"),
                    rs.getString("model"), rs.getString("price"), rs.getString("chipset"), rs.getString("cpu"),
                    rs.getString("camera_primary"), rs.getString("memory_internal") });

        }
    } catch (SQLException err) {
        System.err.println(err);
    }
}

From source file:View.Sending.java

private void clearTable() {
    DefaultTableModel dm = (DefaultTableModel) user_table.getModel();
    int rowCount = dm.getRowCount();
    for (int i = rowCount - 1; i >= 0; i--) {
        dm.removeRow(i);
    }//from w w  w.java2  s .c  om
}