0

I've added several rows to a Jtable, and I don't know if it's possible but I'd like if you click on any cell within a particular column then the connecting row is removed.

Are functions like this possible?

(I'm not asking anyone to do all the work for me. Just asking for information or a tutorial link) thanks :-)

ravibagul91
  • 20,072
  • 5
  • 36
  • 59
  • 6
    See [How to Use Tables](http://docs.oracle.com/javase/tutorial/uiswing/components/table.html). And note that this has nothing to do with Netbanes, so leave it out of the title. – Andrew Thompson Feb 10 '14 at 05:06

1 Answers1

0

attach a mouse listener to the table and when mouse click event occurs if column matches your particular column then remove that row.

tbl.addMouseListener(new MouseAdapter() {

    public void mouseClicked(MouseEvent e) {

        int row = tbl.rowAtPoint(e.getPoint());
        int col = tbl.columnAtPoint(e.getPoint());
        if(col == SPECIFIC_COLUMN_INDEX){
            ((DefaultTableModel)tbl.getModel()).removeRow(row);

        }
    }
});
chathux
  • 821
  • 8
  • 17
  • 2
    What if the rows are sorted? What if the columns are not in model order? What if the OP isn't using a DefaultTableModel? – MadProgrammer Feb 10 '14 at 09:23