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:Main.java

public static void main(String[] argv) throws Exception {
    DefaultTableModel model = new DefaultTableModel();
    JTable table = new JTable(model);

    // Create some data
    model.addColumn("Col1");
    model.addRow(new Object[] { "r1" });
    model.addRow(new Object[] { "r2" });
    model.addRow(new Object[] { "r3" });

    model.removeRow(model.getRowCount() - 1);

    JFrame f = new JFrame();
    f.setSize(300, 300);/*from  w  ww.  ja va 2  s  . c  om*/
    f.add(new JScrollPane(table));
    f.setVisible(true);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    DefaultTableModel model = new DefaultTableModel();
    JTable table = new JTable(model);

    model.addColumn("Col1");
    model.addRow(new Object[] { "r1" });
    model.addRow(new Object[] { "r2" });
    model.addRow(new Object[] { "r3" });

    // Remove the first row
    model.removeRow(0);

    JFrame f = new JFrame();
    f.setSize(300, 300);//from w  w  w.j  a v  a  2s  . com
    f.add(new JScrollPane(table));
    f.setVisible(true);
}

From source file:Main.java

public static void main(String args[]) {
    DefaultTableModel model;
    JTable t = new JTable(model = new DefaultTableModel(0, 1));
    for (int i = 0; i < 10; i++) {
        model.addRow(new Object[] { i });
    }/*  w  ww .  ja v  a  2 s .co  m*/
    JButton removeSelected = new JButton("remove");
    removeSelected.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            int[] selectedRows = t.getSelectedRows();
            for (int i = selectedRows.length - 1; i >= 0; i--) {
                model.removeRow(selectedRows[i]);
                ;
            }
        }
    });
    JFrame f = new JFrame();
    f.add(new JScrollPane(t));
    f.add(removeSelected, BorderLayout.SOUTH);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.pack();
    f.setVisible(true);
}

From source file:Main.java

public static void removeRow(JTable table, int row) {
    DefaultTableModel model = (DefaultTableModel) table.getModel();
    model.removeRow(row);
}

From source file:Main.java

public static void clearAllRows(JTable table) {
    DefaultTableModel tableModel = (DefaultTableModel) table.getModel();
    int rowCount = tableModel.getRowCount();
    for (int i = 0; i < rowCount; i++) {
        tableModel.removeRow(rowCount - i - 1);
    }//w  w  w .j av  a  2  s  .co m
}

From source file:MainWindowLogic.java

static void deleteSelectedRow(JTable where) {
    DefaultTableModel tmp = (DefaultTableModel) where.getModel();
    System.out.println("Wielko tabeli przed usuniciem: " + tmp.getRowCount());
    for (int i = 0; i < tmp.getRowCount(); i++) {
        boolean result = (boolean) tmp.getValueAt(i, 3);
        if (result) {
            tmp.removeRow(i);
            i--;//w  ww  .  ja  v a 2s  .c  o  m
        }

    }
    System.out.println("Wielko tabeli po usuniciu: " + tmp.getRowCount());
    //TODO naprawi numeracje tabeli
    ponumerujWiersze(where);
}

From source file:MainWindowLogic.java

private static void deleteDuplicatsFromTable(JTable jTable) {
    DefaultTableModel tmp = (DefaultTableModel) jTable.getModel();
    boolean somethingChange = false;
    for (int i = 0; i < tmp.getRowCount(); i++) {
        for (int j = i + 1; j < tmp.getRowCount(); j++) {

            if (((double) tmp.getValueAt(i, 1) == (double) tmp.getValueAt(j, 1))
                    && ((double) tmp.getValueAt(i, 2) == (double) tmp.getValueAt(j, 2))) {
                tmp.removeRow(j);
                j--;/*from  w  w  w  .ja  va  2  s .c om*/
                somethingChange = true;

            }
        }
    }
    if (somethingChange) {
        ponumerujWiersze(jTable);
    }
}

From source file:cz.muni.fi.mushroomhunter.restclient.MushroomDeleteSwingWorker.java

@Override
protected void done() {
    try {/*from   w w w . j  a  v  a2 s.co m*/
        get();
    } catch (Exception e) {
        restClient.getlMessageMushrooms().setText("ERROR: server is unavailable.");
        return;
    }
    DefaultTableModel model = (DefaultTableModel) restClient.getTblMushroom().getModel();
    try {
        model.removeRow(get());
    } catch (InterruptedException e) {
        e.printStackTrace();
    } catch (ExecutionException e) {
        e.printStackTrace();
    }
}

From source file:cz.muni.fi.mushroomhunter.restclient.LocationDeleteSwingWorker.java

@Override
protected void done() {
    try {/*w  w  w  .  j av a2 s.  co m*/
        get();
    } catch (Exception e) {
        restClient.getlMessageLocations().setText("ERROR: server is unavailable.");
        return;
    }
    DefaultTableModel model = (DefaultTableModel) restClient.getTblLocation().getModel();
    try {
        model.removeRow(get());
    } catch (InterruptedException e) {
        e.printStackTrace();
    } catch (ExecutionException e) {
        e.printStackTrace();
    }
}

From source file:com.db2eshop.gui.component.table.BookingTable.java

/**
 * <p>destroy.</p>/*from   ww w .j  a va 2s .  co  m*/
 */
public void destroy() {
    this.ready = false;
    DefaultTableModel tableModel = ((DefaultTableModel) this.getModel());
    for (int i = tableModel.getRowCount() - 1; i >= 0; i--) {
        try {
            tableModel.removeRow(i);
        } catch (Exception e) {
            // fuck it
        }
    }
    //      ((DefaultTableModel)this.getModel()).setRowCount(0);
}