⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 e910. removing a row from a jtable component.txt

📁 这里面包含了一百多个JAVA源文件
💻 TXT
字号:
To remove a row of data from a JTable component, you need to remove it from its table model. A simple implementation of a table model that supports the removal of row data is DefaultTableModel. 
When removing a row using DefaultTableModel.removeRow(), the index of the row must be specified. Row indices start from 0. For example, if there are 2 rows in a table, the index of the first row is 0 and the index of the second row is 1. Removing a row at index 0 removes the first row. 

    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"});
    
    // Remove the first row
    model.removeRow(0);
    
    // Remove the last row
    model.removeRow(model.getRowCount()-1);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -