0

I am new to Java and I am trying to add print-preview in my J-frame, I tried a PrintPreview class found on given below link. But problem with this class is after creating an object to PrintPreview class it is asking for (Frame, canvas, page). In frame I pass this for my current frame, and in page "A4" but for convas I didn't getting what to pass in constructor of PrintPreview.

I opened convas2D class for which convas is referring but can't find any help?

Code Source:

Community
  • 1
  • 1
  • Doing print preview in Swing is simply the process of generating a `image of what is to be printed and displaying it. This is typically achieved by generating a `BufferedImage` at the desired page size and using the `Printable` interface, passing the images `Graphics` context to it to generate a page – MadProgrammer Oct 20 '17 at 20:04
  • There's [one example](https://stackoverflow.com/questions/22058738/print-jlabels-icon-in-a-printer-using-a-button/22059079#22059079) and [there's another](https://stackoverflow.com/questions/18460008/printable-prints-bufferedimage-with-incorrect-size/18466550#18466550) – MadProgrammer Oct 20 '17 at 20:06

1 Answers1

0

If you'd like a better help, try submitting your code but see if that piece of code help you:



     class MyCanvas extends Canvas {

          public MyCanvas () {
             setBackground (Color.GRAY);
             setSize(300, 300);
          }

          public void paint (Graphics g) {
             Graphics2D g2;
             g2 = (Graphics2D) g;
             g2.drawString ("It is a custom canvas area", 70, 70);
          }
       }