• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

printing in java 1.4

 
Mario A. Villamizar
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I'm developing a text editor in java and I want to add the printing facility
I have seen many axamples of how to print text in java 1.4 and all of them use an FileInputStream(File) to print text; like this:

I wonder if it is possible to print using some how the text in the JTextPane (I'm using a JTextPane)or DefaultStyledDocument object related with this textPane instead of the FileInputStream, all this because if it happens that you create a new document but you haven't save it and you want to print it, how could you print it, if the fisical file doesn't exist yet?
I hope, I made myself clear. Any tips are welcome!!
Thanks in advance,
 
Wayne L Johnson
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Disclaimer: I haven't tried this myself, but according the the JavaDoc, the "SimpleDoc" constructor takes three parameters:
-- Object printData
-- DocFlavor flavor
-- DocAttributeSet attributes
If you have character data, you can pass in a "String" for the first parameter and use "DocFlavor.STRING" as the flavor. You don't need an underlying file. You might play around with some of the other flavor.
Also, are you using the "DocFlavor.INPUT_STREAM" flavor? If you, keep in mind that there are lots of subclasses of "java.io.InputStream" that you can use. You could use a "StringBufferInputStream" [created using a String] and the "DocFlavor.INPUT_STREAM" flavor to get the same affect a described in the previous paragraph.
You'd have to play around with the different flavors to see how to use the DefaultStyledDocument as an input, but I'd be surprised if it weren't supported.
 
Jan Michael Soan
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We are doing the same but I'm using JTextArea instead, if you want try
this codes bellow, Hope that helps . . .
 
Jan Michael Soan
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Previously asked question :
http://www.coderanch.com/t/336367/GUI/java/Printing-JTextArea
Special thanks to my friend Tom Hill;
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic