Detecting selection changes in JTable

I am trying to find a way to detect changes in a column selected by a user in JTable. I thought a little, and it seems to you that you need to somehow use the TableColumnModelListener to detect changes, but this is not like you are changing the selected column.

+4
source share
3 answers

Instead, you need to add a ListSelectionListener . This will capture the events of choice. Following are some Swing tutorials:

http://download.oracle.com/javase/tutorial/uiswing/events/listselectionlistener.html http://download.oracle.com/javase/tutorial/uiswing/components/table.html#selection

+13
source

From what I read, I think you need to add a MouseListener to your table, which, for example, in mouseClicked, will get a row and column using the following code:

 table.addMouseListener(new MouseListener() { @Override public void mouseClicked(MouseEvent e) { Point pnt = evt.getPoint(); int row = table.rowAtPoint(pnt); int col = table.columnAtPoint(pnt); } } 

It is perfect for you. I used to use a similar thing. By the way, this looks like a problem I found on coderanch, link: http://www.coderanch.com/t/332737/GUI/java/detect-single-click-any-cell

Good luck Boro

+2
source

If "change" you mean changing the cell value, you can use AbstractTableModel and implement fireTableCellUpdated

0
source

Source: https://habr.com/ru/post/1345470/


All Articles