如何在打印的页面上居中 jPanel?
How do I center a jPanel on a page that is printed?
我正在打印收据,这太棒了。打印时是否有直接的方法使 jPanel 在页面上居中?
感谢您的帮助。
有一个半直接的方法。
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);
}
我正在打印收据,这太棒了。打印时是否有直接的方法使 jPanel 在页面上居中?
感谢您的帮助。
有一个半直接的方法。
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);
}