pkl_javaq
asked on
Rudimentary question: Adding MouseListener to JTable rows
I am adding a MouseListener to the rows of a table in order to add Drag and Drop to the rows (with Apple's D & D API).This is as far as I've gotten:
for (int i = 0; i < table.getRowCount(); i++) {
row[ i ].addMouseListener( rowListener );
}
Which returns the following error:
"...Undefined variable: row
row.addMouseListener( rowListener );
^ "
I [i] think [/i] that what I am looking for is to define "row" using something like:
" row = table.grabAllTheRows "
then add the MouseListener to each row:
"row[ i ].addMouseListener( rowListener )".
If I am on the wrong track, please let me know.
for (int i = 0; i < table.getRowCount(); i++) {
row[ i ].addMouseListener( rowListener );
}
Which returns the following error:
"...Undefined variable: row
row.addMouseListener( rowListener );
^ "
I [i] think [/i] that what I am looking for is to define "row" using something like:
" row = table.grabAllTheRows "
then add the MouseListener to each row:
"row[ i ].addMouseListener( rowListener )".
If I am on the wrong track, please let me know.
ASKER
Hi gsatsan;
Thanks for the comment. I tried it and this code:
for (int i = 0; i < table.getRowCount(); i++) {
table.getRow(i).addMouseLi stener(row Listener);
}
returns this error message:
"...Method getRow(int) not found in class javax.swing.JTable.
table.getRow(i).addMouseLi stener(row Listener); "
^
How do I fix it?
Thanks in advance.
Thanks for the comment. I tried it and this code:
for (int i = 0; i < table.getRowCount(); i++) {
table.getRow(i).addMouseLi
}
returns this error message:
"...Method getRow(int) not found in class javax.swing.JTable.
table.getRow(i).addMouseLi
^
How do I fix it?
Thanks in advance.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hi,
getRow() won't help. You need it to be Component to add mouse listener. JTable doesn't have components which correspond to rows. Add MouseListener directly to table and use columnAtPoint() and rowAtPoint() to get column/row information.
Regards,
Igor Bazarny
Brainbench MVP for Java 1
www.brainbench.com
getRow() won't help. You need it to be Component to add mouse listener. JTable doesn't have components which correspond to rows. Add MouseListener directly to table and use columnAtPoint() and rowAtPoint() to get column/row information.
Regards,
Igor Bazarny
Brainbench MVP for Java 1
www.brainbench.com
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
[split points between gsatsan and Ovi]
Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
sudhakar_koundinya
EE Cleanup Volunteer
---------------------
If you feel that your question was not properly addressed, or that none of the comments received were appropriate answers, please post your concern in THIS thread.
I will leave a recommendation in the Cleanup topic area that this question is:
[split points between gsatsan and Ovi]
Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
sudhakar_koundinya
EE Cleanup Volunteer
---------------------
If you feel that your question was not properly addressed, or that none of the comments received were appropriate answers, please post your concern in THIS thread.
table.getRow(i).addMouseLi