user3650125
user3650125

Reputation: 1

insert and delete columns from a button

I have a problem since 2 weeks with my JTable: I created a table with three buttons: "Insert new column", "delete new colunm", "add new column"; I managed to add lines but I can not insert or remove a column. Can you help me?

Upvotes: 0

Views: 65

Answers (1)

Redson
Redson

Reputation: 2140

This is much easier if you extend a AbstractTableModel and use that to display your data. You can make an ArrayList of your data and add/remove from that. The TableModel will update the Table automatically when the ArrayList is changed. The ArrayList contains a class which has all the data that you would have in a row. See the Java Tutorials example from Oracle: http://docs.oracle.com/javase/tutorial/displayCode.html?code=http://docs.oracle.com/javase/tutorial/uiswing/examples/components/TableDemoProject/src/components/TableDemo.java

For custom cells, you can detect from the TableModel which column the cell is in and update its content accordingly.

Upvotes: 1

Related Questions