isuhendro
asked on
JTable, how to get mouse click event here?
Hello experts,
I am writing Swing application using JTable.. exactly what I am doing is based on TableDemo.java that exists in http://java.sun.com/docs/books/tutorial/uiswing/components/table.html
But then I modified the code inside TableModel.java by taking out the inner class of TableModel.java into a separate class, i called it MyTableModel.java.
So the result is MyTableModel.java & TableModel.java. MyTableModel.java will accept an array list as data source. And after I have MyTableModel.java, I would be able to instantiate TableModel.java and passed an instance of MyTableModel during construction time.
Now it's working properly. My question is, I would like to enhance existing code to accept any click event within the table cells. Where should I put Listener class at? And what interface should be implemented by Listener class?
I am writing Swing application using JTable.. exactly what I am doing is based on TableDemo.java that exists in http://java.sun.com/docs/books/tutorial/uiswing/components/table.html
But then I modified the code inside TableModel.java by taking out the inner class of TableModel.java into a separate class, i called it MyTableModel.java.
So the result is MyTableModel.java & TableModel.java. MyTableModel.java will accept an array list as data source. And after I have MyTableModel.java, I would be able to instantiate TableModel.java and passed an instance of MyTableModel during construction time.
Now it's working properly. My question is, I would like to enhance existing code to accept any click event within the table cells. Where should I put Listener class at? And what interface should be implemented by Listener class?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
hi wizard,
thanks for your clue... i am trying your suggestion and able to trap the event.. but if i am not wrong this event is a kind of event that triggered by JTable object, by then can I trap the cell information as well?
I am trying using e.getX() and e.getY().. but the result of X,Y is just cell position in pixel unit, not the cell matrix information.
thanks for your clue... i am trying your suggestion and able to trap the event.. but if i am not wrong this event is a kind of event that triggered by JTable object, by then can I trap the cell information as well?
I am trying using e.getX() and e.getY().. but the result of X,Y is just cell position in pixel unit, not the cell matrix information.
ASKER
hi wizard,
i got to find these below to complete the solution on getting cell matrix information
table.getSelectedRow();
table.getSelectedCount();
Thank you.
i got to find these below to complete the solution on getting cell matrix information
table.getSelectedRow();
table.getSelectedCount();
Thank you.
I'm glad I was able to help
http://www.rgagnon.com/javadetails/java-0336.html