1

I have created a label and added an image to it using the seticon property. Now I want to print that image but I am unable to do so.

I tried with .print(Graphics g) method but I dont know what is that graphics??

If someone can help me in printing the label, I would be really grateful to you.

Thanks

jmj
  • 232,312
  • 42
  • 391
  • 431
Vipul
  • 111
  • 4
  • 13

2 Answers2

3

You don't need to print anything explicitly just try following

 ImageIcon ii=new ImageIcon("PATH_TO_IMAGE_FILE");  

 //Create a label with your image file  
 JLabel label=new JLabel(ii);  

 //Create a window using JFrame with title ( Put image on JLabel )  
 JFrame frame=new JFrame("Put image on JLabel");  

 //Add created label into JFrame  
 frame.add(label);  

Update as per your clarification :

Follow this , and pass label.getGraphics() to printAll() method

jmj
  • 232,312
  • 42
  • 391
  • 431
0

You should implenent Printable interface see for example here

StanislavL
  • 56,113
  • 9
  • 64
  • 93