🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.jbuilder.java.api
1 messages
1 total messages Started by Vlad Tue, 09 Mar 2004 16:21
Printing Text Java 1.4 API
#251
Author: Vlad
Date: Tue, 09 Mar 2004 16:21
53 lines
2519 bytes
Hello all,

I am trying to print the content (Text) of the JEditorPane using Java 1.4
API
In order to do that, i created the method, similar to what is widely
available in boks and on0line:


public void printText(JEditorPane theCode) throws Exception {
Document d = theCode.getDocument();
String text = d.getText(0, d.getLength());
PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
DocFlavor flavor = DocFlavor.CHAR_ARRAY.TEXT_PLAIN;
PrintService printService[] =
PrintServiceLookup.lookupPrintServices(flavor, pras);
PrintService defaultService =
PrintServiceLookup.lookupDefaultPrintService();

>>> PrintService service = ServiceUI.printDialog(null, 200, 200,
printService, defaultService,
DocFlavor.CHAR_ARRAY.TEXT_PLAIN , pras);
if (service != null) {
DocPrintJob job = service.createPrintJob();
PrintJobListener listener = new PrintJobAdapter() {
public void printDataTransferCompleted(PrintJobEvent e) {
System.out.println("Good-bye");
System.exit(0);
}
};

job.addPrintJobListener(listener);
DocAttributeSet das = new HashDocAttributeSet();
Doc doc = new SimpleDoc(text, flavor, das);
job.print(doc, pras);
Thread.sleep(10000);
}
}


I do not want to save the content as a text file. All i want is to print it.
Regardless what kind of flavor i tried to use, i am always getting error
message:

java.lang.IllegalArgumentException: services must be non-null and non-empty

which points to the line marked >>> PrintService service...

Any idea what is wrong. What kind of Flavor shall it be? Any hint will be
highly appreciated.

Thanks,

Vlad
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads