I am getting my receipt to print, which is great. Is there a straight-forward way of centering the jPanel on the page when it is printed?
Thank you for your help.
There's a semi-straightforward way.
public int print(Graphics g, PageFormat pf, int pageIndex) {
Component myPanel =...;
g.translate(pf.getImageableX() + pf.getImageableWidth() / 2 - myPanel.getWidth() / 2, pf.getImageableY() + pf.getImageableHeight() / 2 - myPanel.getHeight() / 2);
//Graphics object has been set up so the printing myPanel with it should now be centered
myPanel.print(g);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.