Re: Swing - Printing Approach Question

From: Jacob (jacob_at_yahoo.com)
Date: 06/16/04


Date: Wed, 16 Jun 2004 10:48:24 +0200

Frank Alviani wrote:

> Hello All,
>
> While I have some simple printing working in the app I'm developing, I'm
> looking for some suggestions as to the approach to take in a more
> complex situation.
>
> I have a dialog that contains a table embedded within a scrolling pane.
> What I'd like to do is to be able to print the entire table, even if it
> is taller than the scrolling pane, as a report. I have no problem with
> doing so as a multi-page print out.
>
> Based on other experiences with trying to resize Swing components after
> they've been realized, I don't feel that trying to resize the dialog is
> a viable approach. Could anybody suggest an approach to take; I'm open
> to anything practical!

An approach I have used with success is to convert
the component to HTML and then pass it on to the
client browser and make *it* do the printing.

Converting a JTable to HTML is fairly simple; I have
a utility class to handle this and it will handle both
cell content, fonts, images, and back-/foreground cell
color, spacing etc.

To pass this on to a nearby browser, simply write the
HTML to a (temporar) file and open with Runtime.exec
(Google for "BrowserLauncher" to get it on all platforms)

Pros:
o All the fine details of printing and printer access
   is left to the browser which is specially designed to
   hanldle these matters. Your app is probably not.
o You get the HTML export for free.
o You get cut/copy (from the browser) functionality
   for free.
o It is probably easier to implement than a custom
   print function using the JDK printing API.

Cons:
o There is one extra keystroke for the user involved.
   (Print in your app which opens the browser, then
    an additional Print from the browser.)
o You lose the fine control over the layout. If this
   *is* an issue, use PDF instead of HTML.



Relevant Pages

  • Re: [opensuse] RFR: Printing From Browsers
    ... Subject: RFR: Printing From Browsers ... I never heard of a browser that prints very well. ... The obvious reason is html just isn't designed for that. ... But that very statement about flowing to fit any window ...
    (SuSE)
  • Re: Tkinter or wxpython?
    ... If you can get them to install a desktop app ... The permission mechanism is admittedly browser dependent. ... not so much for an application platform. ... HTML has non-trivial cross browser differences. ...
    (comp.lang.python)
  • Re: [opensuse] RFR: Printing From Browsers
    ... Subject: RFR: Printing From Browsers ... I never heard of a browser that prints very well. ... The obvious reason is html just isn't designed for that. ... and apply css page-break-before to the pre tag. ...
    (SuSE)
  • Re: Tkinter or wxpython?
    ... If you can get them to install a desktop app ... The permission mechanism is admittedly browser dependent. ... not so much for an application platform. ... HTML has non-trivial cross browser differences. ...
    (comp.lang.python)
  • Re: Tkinter or wxpython?
    ... If you can get them to install a desktop app ... The permission mechanism is admittedly browser dependent. ... But if you write your application with straightforward html ... you tend to have very few platform problems. ...
    (comp.lang.python)