-
Enhancement
-
Resolution: Fixed
-
P4
-
1.2.0
-
beta
-
generic, x86, sparc
-
generic, solaris_2.6, windows_95, windows_nt
Printing is broken in the JDK 1.2 O build. This is a regression. JDK 1.2
FCS K works fine.
Attached are two scripts and two source codes from the tutorial on the
JavaSoft web pages.
printbutton.ksh and printbutton.java are supposed to print a Button. This
functionality is broken. Too reproduce the problem, type "printbutton.ksh" at
the prompt, wait for a frame labeled "printbutton" to appear and click on the
"MyButton" button.
printjbutton.ksh and printjbutton.java are supposed to print a JButton. This
works, but it might be a good idea to try it just before final FCS.
allan.jacobs@Eng 1998-10-23
The third demo in the tutorial, ShapesPrint.java fails in both K and O builds.
ShapesPrint.ksh and ShapesPrint.java are attached.
allan.jacobs@Eng 1998-10-23
I just got two reports from customers that AWT printing in general is broken. I've included the source provided by one of them below. BTW, this is in the final release of JDK 1.2.
I am unable to print components using the print () method
of the Component class.
Whereas the printing of string turns out fine, the Component
doesn't appear at all!
Here is the source code:
import java.awt.*;
import java.awt.event.*;
import java.awt.print.*;
public class testSwing3 extends Frame implements Printable {
public static void main (String[] args) {
Frame f = new testSwing3 ();
f.pack ();
f.setSize (300, 200);
f.setVisible (true);
}
public testSwing3 () {
setLayout (new BorderLayout ());
Panel aCenterP = new Panel ();
aCenterP.setLayout (new FlowLayout ());
aCenterP.add (mBartL = new Label ("Bart"));
aCenterP.add (new Button ("Simpson"));
add (aCenterP, BorderLayout.CENTER);
Button aPrintB = new Button ("Print");
Panel aPrintP = new Panel ();
aPrintP.add (aPrintB);
add (aPrintP, BorderLayout.SOUTH);
aPrintB.addActionListener (
new ActionListener () {
public void actionPerformed (ActionEvent e) {
// Obtain a new PrinterJob
PrinterJob aPJ = PrinterJob.getPrinterJob ();
// Set a Printable object
aPJ.setPrintable (testSwing3.this);
// Begin Printing
try {
if (aPJ.printDialog () == true) {
aPJ.print ();
}
} catch (PrinterException aException) {
System.out.println (aException);
}
}
}
);
}
public int print (Graphics g, PageFormat aPF, int aPageIndex) {
if (aPageIndex > 0) {
return NO_SUCH_PAGE;
}
g.setFont (sFont);
g.setColor (Color.black);
g.drawString ("Page Number: " + (aPageIndex + 1), 150, 150);
//printComponents (g);
//printAll (g);
mBartL.print (g);
return PAGE_EXISTS;
}
private Label mBartL;
private static final Font sFont = new Font ("Courier", Font.PLAIN, 12);
}
=========================================
Much of what is above is confused, stemming from examples which incorrectly
mix the 2D and "1.1" printing APIs.
The 2D printing API was NOT designed to support the print methods
Component.print(Graphics g)
Component.printAll(Graphics g)
Container.printComponents(Graphics g)
These methods are specified to work only with a Graphics instance
obtained from java.awt.PrintJob.getGraphics() which is the "1.1" printing API.
This must be a Graphics which implements java.awt.PrintJob()
See
http://java.sun.com/products/jdk/1.1/docs/guide/awt/designspec/printing.html
This implementation class is therefore different than that provided by the
2D API when it calls its print() method of the Printable interface.
This problem can be avoided for a UI composed entirely of
lightweight components since you can use the paint() or paintAll() methods.
So, since what is required is an augmentation of AWT components
2D printing is not "component-based" as is 1.1 printing
So this is not a bug, but an RFE requesting either that the 2D implementation
be augmented to somehow also implement the 1.1 component printing interfaces
and that the 1.1 printing implementations be made to work with 2D printer
graphics, or that AWT components should be augmented to support 2D
printing .
- relates to
-
JDK-4251821 Java 2D tutorial printing problem.
- Closed