This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
How can we get the image(in png,gif,jpeg)from the icon that is set on a JButton using the setIcon() method?
I need to retrieve this image and save it in any of the availble file formats(jpg,png or gif)
Here is my sample code
So basically I want to retrieve "javalog.gif" and save it somewhere.
I tried to use some Image.getImage() method but dint know how to proceed further.
Any help is much appreciated
a) You should NOT be overriding the paint() method of JFrame.
b) There is no need to do custom painting you can just add an Icon to a label and add the label to the frame
c) If you do need custom painting then you should be overriding the paintComponent() method NOT the paint() method of a JPanel or JComponent.
Read the section from the Swing tutorial for more information about Icons and Custom Painting.