开发者

Printing in Java Swing Components

开发者 https://www.devze.com 2023-04-12 15:16 出处:网络
I have class PrintUtilities, which has the following method to print JPanel and its sub components: public int print(Graphics g, PageFormat pageFormat, int pageIndex)

I have class PrintUtilities, which has the following method to print JPanel and its sub components:

public int print(Graphics g, PageFormat pageFormat, int pageIndex)

There is JLabel within the JPanel, which is right justified and the problem is the printed copy is chopping last digit in the JLabel. I can justify it to Center and the printing works but I don't want to change how it is displayed on the screen.

So, is th开发者_如何学JAVAere a way that I tell the class to display it one way and print it another way? I tried paint(Graphics g) but it will effect the painting the component on the screen.

In short I want to define a way to print JLabel printer without affecting it looks and layout on the screen.


Try placing a border around the JPanel to see if the entire panel gets cut somehow.

Previously, I had a similiar experience and it turned out that my paper size didn't match that in the printer.

Failing that, you might need to investigate scaling your output just a bit so that it fits on the page.

Hope that helps, Ewald

0

精彩评论

暂无评论...
验证码 换一张
取 消