Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Printing a Text File  RSS feed

 
Stephanie Challand
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to figure out how to easily print a .txt file but allow the user to choose the printer.

I have the following code to print the text file directly to the printer and that works PERFECTLY if you have the desired printer as the default.



The problem is we may not have the printer as the default. So I found the following to print showing the dialog box which again works well, but the formatting of the file is all on one line and never wraps.



I need to merget the two I just need to have the print dialog print the file. It should be simple, but apparently not...

Thanks!
 
Knute Snortum
Sheriff
Posts: 3545
85
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I seem to remember that there is a Printer Dialog widget, but you can check here to be sure.

Also, I'm moving this to the Swing forum.
 
Stephanie Challand
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay, I am actually using import java.awt.print.*; to do this though.
I think I finally figured it out...

You can either send a .txt file to the default printer

OR

Show the dialog box and then have to specify the location of everything you want to print
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OR

You could read(...) the file into a JTextArea, set appropriate size and wrap properties and print(). More in the Oracle tutorial on How to Print Text.

I haven't tested this; you just might need to add the text area to a JFrame and pack() to get the desired result.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!