'How to Print Some Items in JForm Using JButton

I'm a newbie in coding. I want to make a shipping label program that printable using JForm Netbeans. The printable text is in a JPanel.

Already looked for the print action code (which hard to found), finally found it, tried it but all failed. The error warning said that the method is not applicable.

    private void buttonprintActionPerformed(java.awt.event.ActionEvent evt) {                                            

        try{
        panelpreview.print(); //error: no suitable method for prints (no argument)
        }

        catch(java.awt.print.PrinterException e){  //error: exception PrinterException is never thrown in body of corresponding try statement
        System.err.format("No Printer Found", e.getMessage());
        }

}

Can you help me so it can work? Thank you in advance.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source