Re: Swing - Printing Approach Question
From: Jacob (jacob_at_yahoo.com)
Date: 06/16/04
- Next message: Frédéric Gédin: "Unable to change the background color of a tab in a tabbed pane"
- Previous message: Carsten Zerbst: "Re: Drag with JTree"
- In reply to: Frank Alviani: "Swing - Printing Approach Question"
- Next in thread: Pacific Guy: "Re: Swing - Printing Approach Question"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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.
- Next message: Frédéric Gédin: "Unable to change the background color of a tab in a tabbed pane"
- Previous message: Carsten Zerbst: "Re: Drag with JTree"
- In reply to: Frank Alviani: "Swing - Printing Approach Question"
- Next in thread: Pacific Guy: "Re: Swing - Printing Approach Question"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|