Remove the last row from a table with DefaultTableModel : Table Model « Swing JFC « Java






Remove the last row from a table with DefaultTableModel

    

import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

public class Main {
  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);
    f.add(new JScrollPane(table));
    f.setVisible(true);
  }
}

   
    
    
    
  








Related examples in the same category

1.Append a row to a table through DefaultTableModel at specified row
2.Remove the first row from a table with DefaultTableModel
3.Move the first row to the end of the table
4.Move the last row to the beginning of the table
5.Move the first two rows to the end of the table
6.Move the last two rows to the start of the table
7.Get all the table data from DefaultTableModel
8.Copy (clone) the data from the second row
9.Overwrite the date from the first row with DefaultTableModel
10.Copy data from a table to a list
11.Insert a new column to a table
12.JTable class using default table models and a convenienceJTable class using default table models and a convenience
13.extends DefaultTableModel to create your own table model and build table from thatextends DefaultTableModel to create your own table model and build table from that
14.Table with a custom TableModelTable with a custom TableModel
15.extends AbstractTableModel to create custom modelextends AbstractTableModel to create custom model
16.Table model is based on call backTable model is based on call back
17.Hard code data in array for TableModelHard code data in array for TableModel
18.A JTable class using default table models and a convenience constructorA JTable class using default table models and a convenience constructor
19.Custom model, POJO and JTableCustom model, POJO and JTable
20.Custom table model, File data based ModelCustom table model, File data based Model
21.Paging or pagable JTable(Table) Model for large data setPaging or pagable JTable(Table) Model for large data set
22.Paging JTable(Table) Model with an input field for dynamically altering the size of a page.Paging JTable(Table) Model with an input field for dynamically altering the size of a page.
23.File data Table: file name, size, type File data Table: file name, size, type
24.Stocks data Table: illustrate the TableModel Stocks data Table: illustrate the TableModel
25.AbstractTableModel backed by HashtableAbstractTableModel backed by Hashtable
26.Fixed data vs dynamic data TableFixed data vs dynamic data Table
27.Use model to control the Editable ColumnsUse model to control the Editable Columns
28.Converts a visible column index to a column index in the model.
29.Converts a column index in the model to a visible column index
30.Returns the visible columns in the order that they appear in the model
31.Appending a Column to a JTable Component using DefaultTableModel
32.Add a column with values.
33.Disable autoCreateColumnsFromModel
34.Add a column without affecting existing columns
35.Remove the first visible column without removing the underlying data
36.Sharing a Table Model Between JTable Components
37.Creating simple JTable using AbstractTableModel
38.Map TableModel
39.TableSorter extends AbstractTableModel
40.TableSorter is a decorator for TableModels
41.Bean Property Table Model
42.A simple extension of JTable that supports the use of a SortableTableModel.
43.This program shows how to build a table from a table modelThis program shows how to build a table from a table model