BusMan29 wrote:Well, I guess it is possible but it is quite uncommon to do this. Usually, you have a "Delete" button outside the table that simply deletes the selected row. If you absolutely do not want to go the usual way, I would still suggest not to go with a button in each row. Instead, add an additional column to your table model that simply holds the String "Delete" (or a nice icon) for all rows. Additionally, add a MouseListener to your JTable and in that listener's mouseClicked method compute the clicked table cell (JTable provides the necessary methods to do so) and if a cell in the last column was clicked, remove the corresponding row. This saves you the hazzle of writing possibly complicated TableCellRenderer and TableCellEditor implementations to make JButtons work in JTable.
1. May I add a JButton at the end of each row in JTable?
I would like to add a JButton at the end of each row. When we click this JButton, the whole row is deleted.
thomas.behr wrote:<tt>TableCellRenderer</tt> is the intended way to do this kind of stuff. And once you undertdood how <tt>TableCellEditor</tt> work it's not complicated at all.
This saves you the hazzle of writing possibly complicated TableCellRenderer and TableCellEditor implementations to make JButtons work in JTable.
BusMan29 wrote:That kind of question cannot be exhaustively answered, because there can be any number of triggers for removing rows in a JTable.
Suppose I would like to delete a row in JTable, how may I do it other than adding a JButton at the end of the JTable?