Does anybody know how to remove a row from a JTABLE?
Bala Hari
Greenhorn
Joined: Nov 14, 2001
Posts: 7
posted
0
To remove a row from a Jtable use the flg. method yourJTable.removeRow(rownum);
Jennifer Garrett
Greenhorn
Joined: Oct 31, 2001
Posts: 13
posted
0
I think you need to use DefaultTableModel for adding and removing rows. Your code might be something like this: String[] mycolumns = {"column 1 title", "column 2 title"}; String[][] mydata = {{"foo", "bar"}, {"aaa", "bbb"}}; DefaultTableModel mytableModel = new DefaultTableModel(mydata, mycolumns); JTable mytable = new JTable(mytableModel); JScrollPane myscrollpane = new JScrollPane(mytable); // ... somehwere later, whenever you want to remove a row... int rowNumber = 0; mytableModel.removeRow(rowNumber); // remove the first row
Need a bit more help on this JTable please... Is there any way to set the widths of the colums? So if I wanted the first colum to start up twice the width of the second (without manually having to drag it), how would I do that? Thanks.