How to draw grid using swing class Java and detect mouse position when click and drag
I am trying to create a grid UI (5*5) using Swing classes. I tried a nested loop and adding a jPanel dynamically to the jFrame. And I also tried to change the background colour of each jPanel when user clicks and drops over it. But with my code there are huge gaps between each cell and I can't get the drag event to work. public class clsCanvasPanel extends JPanel { private static final int intRows = 5; private static final int intCols = 5; private List<JPanel> jpllist = new ArrayList<JPanel>(); public clsCanvasPanel() { /* * * Add eventListener to individual JPanel within CanvasPanel * * *