From owner-freebsd-java@FreeBSD.ORG Mon Nov 29 19:45:50 2004 Return-Path: Delivered-To: freebsd-java@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 9382516A4CE for ; Mon, 29 Nov 2004 19:45:50 +0000 (GMT) Received: from webmail-outgoing.us4.outblaze.com (webmail-outgoing.us4.outblaze.com [205.158.62.67]) by mx1.FreeBSD.org (Postfix) with ESMTP id 6DE9E43D5C for ; Mon, 29 Nov 2004 19:45:50 +0000 (GMT) (envelope-from myloveforyou@loveable.com) Received: from wfilter.us4.outblaze.com (wfilter.us4.outblaze.com [205.158.62.180])22FAA1800373 for ; Mon, 29 Nov 2004 19:45:50 +0000 (GMT) X-OB-Received: from unknown (205.158.62.49) by wfilter.us4.outblaze.com; 29 Nov 2004 19:45:46 -0000 Received: by ws1-1.us4.outblaze.com (Postfix, from userid 1001) id 734D04BDAA; Mon, 29 Nov 2004 19:45:46 +0000 (GMT) Content-Type: text/plain; charset="iso-8859-1" Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Received: from [195.44.169.19] by ws1-1.us4.outblaze.com with http for myloveforyou@loveable.com; Mon, 29 Nov 2004 14:45:46 -0500 From: "Lukman Jaji" To: freebsd-java@freebsd.org Date: Mon, 29 Nov 2004 14:45:46 -0500 X-Originating-Ip: 195.44.169.19 X-Originating-Server: ws1-1.us4.outblaze.com Message-Id: <20041129194546.734D04BDAA@ws1-1.us4.outblaze.com> Subject: JAVA PRINTING X-BeenThere: freebsd-java@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Porting Java to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 29 Nov 2004 19:45:50 -0000 Hello, I am trying really hard to print a textarea in a frame. It prints string to= graphics via printjob but it does not deal with word wrap so that when I p= rint, I lose all the info that doesn't fit in the paper (to the right of th= e paper). Here's my code implementing the command: public void printCommand() { PrintJob pjob =3D getToolkit().getPrintJob(FileViewer.this, "FilePrinter", = printprefs); if (pjob !=3D null) { Graphics pg =3D pjob.getGraphics(); if (pg !=3D null) { pg.translate(75, 75); Dimension size =3D this.getSize(); // Set a clipping region so our scribbles don't go outside the border // On-screen this happens automatically, but not on paper. //pg.setClip(0, 0, size.width, size.height); String s =3D textarea.getText(); printLongString(pjob, pg, s); pg.dispose(); } pjob.end(); } } // Print string to graphics via printjob // Does not deal with word wrap or tabs void printLongString (PrintJob pjob, Graphics pg, String s) { int pageNum =3D 1; int linesForThisPage =3D 0; int linesForThisJob =3D 0; // Note: String is immutable so won't change while printing. if (!(pg instanceof PrintGraphics)) { throw new IllegalArgumentException ("Graphics context not PrintGraphics"); } StringReader sr =3D new StringReader (s); LineNumberReader lnr =3D new LineNumberReader (sr); String nextLine; int pageHeight =3D pjob.getPageDimension().height; Font myfont =3D new Font("Tahoma", Font.PLAIN, 9); //have to set the font to get any output pg.setFont (myfont); FontMetrics fm =3D pg.getFontMetrics(myfont); int fontHeight =3D fm.getHeight(); int fontDescent =3D fm.getDescent(); int curHeight =3D 0; try { do { nextLine =3D lnr.readLine(); if (nextLine !=3D null) {=20 if ((curHeight + fontHeight) > pageHeight) { // New Page=20 System.out.println ("" + linesForThisPage + " lines printed for page " + pa= geNum); pageNum++; linesForThisPage =3D 0; pg.dispose(); pg =3D pjob.getGraphics(); if (pg !=3D null) { pg.setFont (myfont); } curHeight =3D 0; } curHeight +=3D fontHeight; if (pg !=3D null) { pg.drawString (nextLine, 0, curHeight - fontDescent); linesForThisPage++; linesForThisJob++; } else { System.out.println ("pg null"); } } } while (nextLine !=3D null); } catch (EOFException eof) { // Fine, ignore } catch (Throwable t) { // Anything else t.printStackTrace(); } System.out.println ("" + linesForThisPage + " lines printed for page " + pa= geNum); System.out.println ("pages printed: " + pageNum); System.out.println ("total lines printed: " + linesForThisJob); } Can anyboy help me to implemenet wordwrap when printing? Any help will be greatly appreciated and thank you so much in advance.... Thanks!!!=20 --=20 ___________________________________________________________ Sign-up for Ads Free at Mail.com http://promo.mail.com/adsfreejump.htm