I was looking for this answer in here but didn’t find it, so I’m writing my own answer below if someone need it.
Feel free to correct anything if needed.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
So, in order to make a solution for both cases (JList and JTable) I made a custom listener that will be applied to the lists and table in question.
The listener is :
Notice that this works well in
SINGLE_SELECCTION, but if we want to useMULTIPLE_INTERVAL_SELECTIONorSINGLE_INTERVAL_SELECTIONI would recommend not to overridemouseReleased(MouseEvent e)as it will clear selection if the mouse button is released outside the selection range.PD: for this last point I’ve done the following fix: