aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Printing Jpanel Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Printing Jpanel" Watch "Printing Jpanel" New topic
Author

Printing Jpanel

Talha-bin -Shakir
Ranch Hand

Joined: Jan 26, 2006
Posts: 32
I have a picture on a JPanel and the size of Panel is 700x440 I need to print this panel with the size of 243x154 as a card size. I used paper.setSize(243,154) but still its printing with the same 700x440 size. How I print this with the 243x154 size. If i save Panel or save picture with this size the quality of picture effected. So I have to print this 700x440 Panel with 253x154 size. Please anyone help. Here is my Code:



Thanks
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19761
    
  20

Besides translating, you'll need to scale your graphics object as well.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Talha-bin -Shakir
Ranch Hand

Joined: Jan 26, 2006
Posts: 32
i didn't get what do you mean should i need to scale like this:

g2.scale(243,154);

or

g2.scale(pf.getImageableX(), pf.getImageableY());

I have tried both ways but still no result. so can you please elaborate in a bit detail for me thanks.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19761
    
  20

Your component is 700x440, your page is 253x154. The scale should therefore be the ratio between the two: 253 / 770 and 154 / 440. Remember to cast to float / double before dividing though, or both will be 0.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Printing Jpanel