[英]How do I center a jPanel on a page that is printed?
我正在打印收據,這很棒。 在打印jPanel時,是否有直接的方式將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);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.