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,
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.