JTable listener problem

Posted by newbie123 on Stack Overflow See other posts from Stack Overflow or by newbie123
Published on 2010-05-29T15:17:02Z Indexed on 2010/05/29 15:22 UTC
Read the original article Hit count: 512

Filed under:
|
|

I added a mouse clicked listner to my jtable, when i double click the row, will pop up an window accordingly.

jTable.addMouseListener(new java.awt.event.MouseAdapter() {

public void mouseClicked(java.awt.event.MouseEvent e) { double amount = Double.parseDouble(jTable.getValueAt(getSelectedRow(), 4).toString()); String remarks = jTable.getValueAt(getSelectedRow(), 3).toString(); String transactionID = jTable.getValueAt(getSelectedRow(), 1).toString(); new EditFrame(...) } });

This code I used to retrieve the row selected row.

public int getSelectedRow() {

jTable.getSelectionModel().addListSelectionListener( new ListSelectionListener() { public void valueChanged(ListSelectionEvent event) { int viewRow = jTable.getSelectedRow(); selectedRow = viewRow; System.out.println(viewRow); } }); return selectedRow; }

In my case, I realised when I clicked the second row in the first time, I get null for selectedRow, only when I select first row then second row, I then can get the correct data. And If I removed the mouse listener the problem then be solved. Is it because I doing something wrong at the mouse click listener?

© Stack Overflow or respective owner

Related posts about mouse

Related posts about jtable