I am adding and deleting components dynamically in a JPanel. Adding and deleting functionality works fine but when I delete the component it deletes the last component rather than the component to be deleted.
JPanel
How can I solve this issue?