Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Java应用程序中打印JFrame(使用Netbeans)_Java_User Interface_Netbeans_Printing - Fatal编程技术网

在Java应用程序中打印JFrame(使用Netbeans)

在Java应用程序中打印JFrame(使用Netbeans),java,user-interface,netbeans,printing,Java,User Interface,Netbeans,Printing,我正在尝试打印JFrame的内容,但是,通过查看不同的教程,我仍然没有任何运气。。。目前,用于打印的部分代码是 public class View_Check extends javax.swing.JFrame implements Printable{ JFrame frameToPrint; public int print(Graphics g, PageFormat pf, int page) throws PrinterException

我正在尝试打印JFrame的内容,但是,通过查看不同的教程,我仍然没有任何运气。。。目前,用于打印的部分代码是

  public class View_Check extends javax.swing.JFrame implements Printable{

  JFrame frameToPrint;


   public int print(Graphics g, PageFormat pf, int page) throws
            PrinterException {
        if (page > 0) {
            return NO_SUCH_PAGE;
        }

        Graphics2D g2d = (Graphics2D) g;
        g2d.translate(pf.getImageableX(), pf.getImageableY());
        frameToPrint.printAll(g);
        return PAGE_EXISTS;
    }
点击按钮(jButton2)

我确信缺少了一些东西,但是尝试添加“JFrame f”来查看\u检查并没有帮助。。。新的(视图检查(f))或者是因为找不到f,所以ant NetBeans正在变成一棵有红线的圣诞树

以防万一这里有一个

public View_Check( Model_Customer cust)  {

        initComponents();
        lblinfo1.setVisible(false);
        customer = cust;
        lblname.setText(customer.GetFName());
        lblsurname.setText(customer.GetLName());
        lblMake.setText(customer.GetMake());
        lblModel.setText(customer.GetModel());
        lblEngine.setText(customer.GetEngine());
        lblRegistration.setText(customer.GetRegistration());
        lblMileage.setText(customer.GetMileage());
        String date = new SimpleDateFormat("dd-MM-yyyy").format(new Date());
        lblDate.setText(date);
        lblPostcode.setText(customer.GetPostcode());
        lblNumber.setText(customer.GetNumber());               
    }

更改了FrameTopPrint.printAll(g);对此,printAll(g);工作起来很有魅力:)谢谢你的帮助

试着让JFrame frameToPrint保持静态 看看它是否解决了问题。

您可以看一看-确保框架大小正确。。。
public View_Check( Model_Customer cust)  {

        initComponents();
        lblinfo1.setVisible(false);
        customer = cust;
        lblname.setText(customer.GetFName());
        lblsurname.setText(customer.GetLName());
        lblMake.setText(customer.GetMake());
        lblModel.setText(customer.GetModel());
        lblEngine.setText(customer.GetEngine());
        lblRegistration.setText(customer.GetRegistration());
        lblMileage.setText(customer.GetMileage());
        String date = new SimpleDateFormat("dd-MM-yyyy").format(new Date());
        lblDate.setText(date);
        lblPostcode.setText(customer.GetPostcode());
        lblNumber.setText(customer.GetNumber());               
    }