Resizing JPanel to prepare for printing without removing it from its original position
Posted
by Lesman
on Stack Overflow
See other posts from Stack Overflow
or by Lesman
Published on 2009-08-02T23:06:31Z
Indexed on
2010/03/17
15:01 UTC
Read the original article
Hit count: 198
In my program I frequently need to print various JComponents (generally JPanels) and I like them to be full-page. The way I do it now is by using the following code:
g2d.scale(pf.getImageableWidth()/componentToPrint.getWidth(), pf.getImageableHeight()/componentToPrint.getHeight());
but this often stretches or otherwise deforms whatever I am trying to print, and I would much prefer to do something that re-sized intelligently, perhaps a functional version of:
componentToPrint.setSize(pf.ImageableWidth(), pf.ImageableHeight);
or say adding the component into a new JFrame and then setting the frame size (problem is components can't exist in two place at once). I wouldn't care if the resizing would make the rest of the GUI look terrible, as long as it is something that can easily be reset.
Is there any way to do this?
© Stack Overflow or respective owner