|
Quick Lists
|
|
Bug ID:
|
6194767
|
|
Votes
|
0
|
|
Synopsis
|
JComponent should have an isPrinting() method
|
|
Category
|
java:classes_swing
|
|
Reported Against
|
rc
|
|
Release Fixed
|
mustang(b16)
|
|
State
|
10-Fix Delivered,
bug
|
|
Priority:
|
4-Low
|
|
Related Bugs
|
6260638
,
4791650
|
|
Submit Date
|
12-NOV-2004
|
|
Description
|
5.0 added printing support to JTable. While the table printing support deals with the details of hiding selection and focus during printing, developers want an easy way to customize other aspects of their printouts.
For example, one developer commented that he had a table with alternating row colors. In a printed output he didn't want these colors. He needed some way for his renderers to know that printing was going on.
We need to expose an isPrinting() flag for this purpose.
xxxxx@xxxxx 2004-11-12 18:45:47 GMT
|
|
Work Around
|
Until this flag is made public, developers can simply override JTable's print(Graphics) method to set and clear their own flag:
public void print(Graphics g) {
isPrinting = true;
try {
super.print(g);
} finally {
isPrinting = false;
}
}
xxxxx@xxxxx 2004-11-12 18:45:47 GMT
|
|
Evaluation
|
I filed this, I agree. The approach will be to add an isPrinting() flag to JComponent to be set and cleared whenever print(Graphics) is called. Additionally, JTable will be changed to look at this flag instead of the one it currently maintains separately. This will affect existing code that uses the print(Graphics) method but it is expected that developers will want selection and focus turned off during printing, regardless of the method they take. See the work-around section for details on how developers can customize their printing until this flag is released.
xxxxx@xxxxx 2004-11-12 18:45:47 GMT
You don't need a new API to know you are printing.
All you need to do in your app is write
if (graphics instanceof PrinterGraphics) ..
This works now (1.5).
Where that wouldn't work is if you want to know this outside of
the context of the rendering. But testing for PrinterGraphics is
more precise in that if you have to repaint the screen because
of an expose event, isPrinting() may mislead you into repainting
the screen in the way you intended to print. If you test for
the graphics you know for sure if you are printing (or not).
xxxxx@xxxxx 2004-11-12 20:44:09 GMT
======
We have SwingUtilities2.isPrinting(Graphics g) already.
It is package private but could be public as well.
xxxxx@xxxxx 2004-11-13 00:50:29 GMT
======
Thanks xxxxx@xxxxx - that's another great way for the developer to know that they're printing. What I'd like to offer with the new isPrinting() in particular, is a way for renderers (which don't get a graphics when they're configured) to know if the associated component is printing. And by overriding it in JTable they can customize whether or not we show the selection/focus in the printouts. Also, JComponent already keeps a flag to say whether or not it is printing (used to determine its use of double buffering, etc.) and I'd simply like to expose it. NOTE that there will not be any problem with getting mixed up in expose events. This flag is set by the print(Graphics) method which is called only when rendering for printing. It will be clearly documented that it should not be confused with other higher level printing APIs like JTable.print().
xxxxx@xxxxx 2004-11-16 15:44:47 GMT
Just decided: JTable.print() will fire "printing" property change events as it changes the value of isPrinting().
xxxxx@xxxxx 2004-11-30 19:37:42 GMT
|
|
Comments
|
PLEASE NOTE: JDK6 is formerly known as Project Mustang
|
|
|
 |