• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Printing Jpanel

 
Talha-bin -Shakir
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20494
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Besides translating, you'll need to scale your graphics object as well.
 
Talha-bin -Shakir
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20494
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic