How to get X and Y index of element inside GridLayout?

This example shows how to create a grid button that knows its location on the grid. The method getGridButton() shows how to obtain a button reference efficiently based on its grid coordinates, and the action listener shows that the clicked and found buttons are identical. package gui; import java.awt.EventQueue; import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; … Read more

Loading resources like images while running project distributed as JAR archive

First of all, change this line : image = ImageIO.read(getClass().getClassLoader().getResource(“resources/icon.gif”)); to this : image = ImageIO.read(getClass().getResource(“/resources/icon.gif”)); More info, on as to where lies the difference between the two approaches, can be found on this thread – Different ways of loading a Resource For Eclipse: How to add Images to your Resource Folder in the Project … Read more