0

I want to add an Action Listener (print button) which after the action is performed will print out the whole window (GUI form).

printButton.addActionListener(new ActionListener() {
            @Override
            public PrinterJob actionPerformed(ActionEvent e) {
                PrinterJob job = PrinterJob.getPrinterJob();
                return job;
            }
        });

    }

I have already implemented:

import java.awt.print.Printable;

The program responded with the message that the window is read-only

  • For [example](https://stackoverflow.com/questions/22241711/setting-print-size-of-a-jlabel-and-put-a-jradiobutton-on-the-print/22244116#22244116), [example](https://stackoverflow.com/questions/13558152/how-can-i-print-a-custom-paper-size-cheques-8-x-4/13558335#13558335), [example](https://stackoverflow.com/questions/12764634/printing-a-jframe-and-its-components/12765916#12765916), [example](https://stackoverflow.com/questions/16728397/print-the-whole-program-layout/16728708#16728708) – MadProgrammer Feb 06 '22 at 21:53
  • [example](https://stackoverflow.com/questions/22058738/print-jlabels-icon-in-a-printer-using-a-button/22059079#22059079), [example](https://stackoverflow.com/questions/35759522/scale-jcomponent-to-fit-page-page/35760408#35760408), [example](https://stackoverflow.com/questions/46969244/print-jframe-with-setvisiblefalse/46970091#46970091), [example](https://stackoverflow.com/questions/29070689/printing-a-2-pages-of-jframe-in-java/29137211#29137211), [example](https://stackoverflow.com/questions/32000888/how-to-print-whole-jpanel-with-a-footer-in-every-page-in-java-swing/32001433#32001433) – MadProgrammer Feb 06 '22 at 21:54
  • [example](https://stackoverflow.com/questions/17904518/fit-scale-jcomponent-to-page-being-printed/17961911#17961911), [example](https://stackoverflow.com/questions/22241711/setting-print-size-of-a-jlabel-and-put-a-jradiobutton-on-the-print/22242658#22242658) – MadProgrammer Feb 06 '22 at 21:54
  • I think it's important to note a few things. Designing for the screen and designing for the printer are two different concepts, each with their own individual needs. Simply printing the component(s) isn't always the best solution. While some of the Swing components provide complex printing support, it's not always the best solution and even the most basic of outputs would benefit from a separate printing workflow. To that end, I might recommend taking the time to look at things like Jasper Reports – MadProgrammer Feb 06 '22 at 21:57

0 Answers0