import javax.swing.JFrame;
import javax.swing.JTable;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.DefaultTableModel;
public class JTableExample extends JFrame{
Object[][] data = {{9,8,7,6},{7,6,5},{6,5,4}};
String[] title = {"c1", "c2", "c3"};
public JTableExample(){
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
DefaultTableModel dtm = new DefaultTableModel(data, title);
table.setModel(dtm);
this.getContentPane().add(new JScrollPane(table),BorderLayout.CENTER);
//delete row 2
((DefaultTableModel)table.getModel()).removeRow(1);
pack();
}
public static void main(String[] args) {
new JTableExample();
}
}
class Model extends AbstractTableModel{JTable HashMap Model:
List< object> data = new ArrayList< object> ();
public void removeRow(int line){
this.data.remove(line);
}
}
class Model extends AbstractTableModel{And if you're using a two-dimensional array whose elements aren't stored dynamically, then you'll have problems, because there's no function that removes a row from an array. So, you're going to create an offset that will have an unnecessary complexity of (n-k)*m(k; line index) caused by the time and number of operations required to offset all elements.
HashMap< Integer, Object[]> data = new HashMap< Integer, Object[]> ();
public void removeRow(int line){
this.data.remove(line);
}
}
Please disable your ad blocker and refresh the window to use this website.