How can I get the JButton element from within the ImageIcon class?
Yes you can do it using ImageIcon#getImageObserver() and ImageIcon#setImageObserver().
Sample code:
ImageIcon icon = new ImageIcon();
JButton btn = new JButton(icon);
// set the Image Observer of the ImageIcon
icon.setImageObserver(btn);
...
// get Image Observer back from ImageIcon
JButton observer = (JButton) icon.getImageObserver();
if (observer == btn) {
System.out.println("We got the JButton from ImageIcon");
}
output:
We got the JButton from ImageIcon