I have a JTextArea that I need to be able to print off from the printer. This is the kid of text that is in the JTextArea

GLEN ROGERS
47 PINE AVENUE, CARRICKFERGUS, BT38 8EE, 07824771114

733KIA

2012/07/03
DEVICE; OTHER - GIVE MAKE AND MODEL

PACKARD BELL EASYNOTE TN?

WINDOWS 7 INSTALL

That would look quite bare on a sheet of paper, I would like to print this out but add a logo to the top of the page and an address and phone to the bottom (shops addy and shops logo)

Is this going to be possible?
Thanks

Edited 4 Years Ago by GlenRogers

I haven't looked at this yet, something else needs sorted first.
But i will be looking into both of your suggestion, thank you very much
Glen

I can't get my head round eithher of these! Is there a simpler way to do this?
Thanks

I'm with stultuske on this one. Use the knowledge you already have to construct the whole page as if it was a JFrame, then use the print api to print that instead of displaying it on the screen.
ps sorry @softswing, but I would advise some caution about roseindia - their quality control doesn't seem too good, so the code there may be OK, or it may be badly out of date, or it may just be bad code... and if you're a learner it can be hard to tell which is which.

When I construct the page as a JFrame, do I do it in a seperate class?
On the JFrame I will have a logo at the top, addres details at the bottom, and then is it a JTextArea I should have in the middle to put my text from the results JTextArea?

Basically you can construct your JFrame any way you want. Read through the link that stultuske provided, especially "Printing the Contents of a User Interface" page

Hi,
I've got a JPanel which hold all my other components: image, JEditorPane and 2 JLabels. I can print this JPanel but it cuts of the right side of the panel, how I can I make the JPanel fit entirely on the page??
This is the cod I am using right now:

  public void processPrint()
  {
      PrinterJob pj = PrinterJob.getPrinterJob();
      pj.setJobName(" Print Component ");

      pj.setPrintable (new Printable() {    
            @Override
      public int print(Graphics pg, PageFormat pf, int pageNum)
      {
          if (pageNum > 0)
          {
              return Printable.NO_SUCH_PAGE;
          }

          Graphics2D g2 = (Graphics2D) pg;
          g2.translate(pf.getImageableX(), pf.getImageableY());
          everything.paint(g2);
          return Printable.PAGE_EXISTS;
     }
  });
  if (pj.printDialog() == false)
  return;
  try 
  {
        pj.print();
  } 
  catch (PrinterException ex) 
  {
        JOptionPane.showMessageDialog(null, "Error" + ex, "Error", JOptionPane.WARNING_MESSAGE);
  }
}

Thanks

Edited 4 Years Ago by GlenRogers

Is there any other way to do this? I tried what you suggested, but the image, text etc ends up squashed looking.
Thanks

I messed about with scale() and rejigging the document and got it to look acceptable when printed.
Thanks

This question has already been answered. Start a new discussion instead.