I am trying to add tool tip to every image I draw on the JPanel
. But each time a new Image is added, the tool tip text gets over written because I am using this.setToolTipText(text);
for every image.
As seen in the image, the second traffic light image shows tool tip that reads traffic light 3 because that was the last image added.
Can someone please tell me another way to add unique tool tips? I searched for possible solutions but could not find any.
//Drawing the blockage on the road
g.drawImage(blockageImage, bestMatchRUnit.getX(), bestMatchRUnit.getY(), 5, 5, this);
this.setToolTipText("Blockage: " + blockageIndex); //setting the tooltip
blockageIndex++;