0

大家好,我正在尝试打印我所有的挥杆组件我找到了这段代码谁能解释一下我的作用是gettoolkit()什么?这是代码

Toolkit tkp = jPanel9.getToolkit();
PrintJob pjp = tkp.getPrintJob(this, null, null);
Graphics g = pjp.getGraphics();
jPanel9.print(g);

我可以打印一个摆动组件托架调用print()方法,但不能打印jpanel

4

1 回答 1

2

You should use printAll over print

From the JavaDocs

public void print(Graphics g)

Prints this component. Applications should override this method for components that must do special processing before being printed or should be printed differently than they are painted. The default implementation of this method calls the paint method.

The origin of the graphics context, its (0, 0) coordinate point, is the top-left corner of this component. The clipping region of the graphics context is the bounding rectangle of this component.

And PrintAll...

public void printAll(Graphics g)

Prints this component and all of its subcomponents. The origin of the graphics context, its (0, 0) coordinate point, is the top-left corner of this component. The clipping region of the graphics context is the bounding rectangle of this component.

Possible examples...

于 2013-08-20T05:02:27.523 回答