Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts

    Question printing text from JTextArea

    Hello,

    I'm trying to print text from a JTextArea,


    this will bring up the print dialog, however when I click print, nothing is sent to the printer.

    PrinterJob pj = PrinterJob.getPrinterJob();
    pj.printDialog();


    how can I tell the printDialog to print the text from the JTextArea?

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    You can't. Printing requires you to write a class that implements the Printable interface where you would render the graphic for the print. What you can do is write a class (anonymous is fine as well) which is given the text of the JTextArea that then creates the graphics using the graphic's drawString() method.

    Once you have that, you use pj.setPrintable(myPrintableObject); then issue pj.print().
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #3
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts
    Ok, another question for you, is there anyone to access the "print properties" using just print() ? it's always grayed out.

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Do you mean on the actual print dialog? I don't think there is anything you could force there. Been awhile (like, school time while) that I printed with Java, but I believe it chained the print to the OS level print handling. If its greyed out options, that would typically be a driver level. I'll check the docs after to see if I can find anything in the print properties though.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •