🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.api
Article #251

Printing Text Java 1.4 API

#251
From: 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
Technical Details
Message-ID: <404def19$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 1089d0,c402abaaf126f2d,start
X-Google-Attributes: gid1089d0,public
X-Google-ArrivalTime: 2004-03-09 08:40:39 PST
Reply-To: "Vlad" <makarovv@mskcc.org>
From: "Vlad" <makarovv@mskcc.org>
Newsgroups: borland.public.jbuilder.java.api
Subject: Printing Text Java 1.4 API
Date: Tue, 9 Mar 2004 11:21:46 -0500
Lines: 55
Organization: mskcc
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
NNTP-Posting-Host: 140.163.254.136
Message-ID: <404def19$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1078849305 140.163.254.136 (9 Mar 2004 08:21:45 -0800)
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail