So I have a JPanel that is populated by the contents of a 2D array. I have a mouse listener which changes the colour of a cell when pressed. My question is, is it possible to have the user drag the mouse over a line of cells and colour them all in succession? I have looked into mouse motion listener but this doesn't seem to help.
Any ideas?
You can use the
mouseDragged()method of theMouseMotionListenerin conjunction with themousePressed()method of theMouseListener.The
mousePressed()method will handle a simple click without movement, andmouseDragged()will handle any dragging done. I combined the code I wrote for my answer to your original question here to better clarify what everything does, and a response on your other question would be very much appreciated.