JDK-4645377 : java2D printing in 1.3.1 is requested to be improved
  • Type: Enhancement
  • Component: client-libs
  • Sub-Component: 2d
  • Affected Version: 1.3.1
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: solaris_7
  • CPU: sparc
  • Submitted: 2002-03-01
  • Updated: 2002-03-01
  • Resolved: 2002-03-01
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
1.4.0 1.4Fixed
Related Reports
Relates :  
Relates :  
Description
When printing Java2D windows under UNIX using JDK 1.3.x,
the print dialog box is not very useable.  You cannot change the
printer without invoking the PSPrinterJob.printDialog() method.
However, this dialog does not return any properties that can be
re-used for its next invocation.  Likewise, you cannot print to a
file and have it remember the last destination file selection.


Cadence Design Systems Inc. has developed a simple workaround for the severe limitations of the Java2D print dialog box.  The existing dialog box shipped with JDK 1.3.1 exhibits the following undesirable behavior:

1.  Not being able to specify or change the default printer in
the dialog box and remember it for future invocations.  Users
with long network printer names have difficulty using it.

2.  Not being able to select a printer from a pull-down menu
list.

3.  The print dialog box looks and feels completely different
from all the other dialog boxes in the Swing toolkit.  The
print-to-file dialog has similar characteristics.

4.  The dialog box always pops up in the upper right hand corner
of the window every time.

5.  Many print attributes are missing altogether.




// Test class to demonstrate lack of features of PrinterJob.printDialog()

import java.awt.geom.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.print.PrinterJob;
import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
import java.awt.print.*;

// Compile with: javac TestPrint.java
// Run with:     java TestPrint

public class TestPrint extends JPanel implements Printable, ActionListener {

    final static Color bg = Color.white;
    final static Color fg = Color.black;

    final static BasicStroke stroke = new BasicStroke(2.0f);
    final static JButton button = new JButton("Print");

    public TestPrint() {
		setBackground(bg);
        button.addActionListener(this);
    }

	public void actionPerformed(ActionEvent e) {

        if (e.getSource() instanceof JButton) {   
	    
			JFrame jb = new JFrame();

			PrinterJob printJob = PrinterJob.getPrinterJob();

			if (printJob != null) {
				printJob.setPrintable(this);
				if (printJob.printDialog()) {
					try {
						printJob.print();  
					} catch (Exception ex) {
						ex.printStackTrace();
					}
				}
			}
		}
	}


    public void paintComponent(Graphics g) {
		super.paintComponent(g);
		Graphics2D g2 = (Graphics2D) g;
		drawShapes(g2);
	}

	public void drawShapes(Graphics2D g2){

        g2.setPaint(fg);
         
        g2.setStroke(stroke);
        g2.draw(new Rectangle2D.Double(10, 10, 210, 150));
        
    }

    public int print(Graphics g, PageFormat pf, int pi) throws PrinterException
	{
        if (pi >= 1) {
            return Printable.NO_SUCH_PAGE;
		}
		drawShapes((Graphics2D) g);
        return Printable.PAGE_EXISTS;
    }
  
	public static void main(String s[]) {
		WindowListener l = new WindowAdapter() {
				public void windowClosing(WindowEvent e) {System.exit(0);}
				public void windowClosed(WindowEvent e) {System.exit(0);}
			};

		JFrame f = new JFrame();
		f.addWindowListener(l);
		JPanel panel = new JPanel();
		panel.add(button);
		f.getContentPane().add(BorderLayout.SOUTH, panel);
		f.getContentPane().add(BorderLayout.CENTER, new TestPrint());
		f.setSize(250, 250);
		
		f.show();
    }

}

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: 1.4 FIXED IN: 1.4 INTEGRATED IN: 1.4
14-06-2004

WORK AROUND Cadence Design Systems has developed a very simple fix to avoid the use of the PrinterJob.printDialog() method altogether. By making several of the private variables in the PSPrinterJob and PSPrintJob classes public, it is possible to control the print job without having to invoke the printDialog() method. The variables that need to be made public are the following: PSPrinterJob.mDestType PSPrinterJob.mDestination PSPrinterJob.mOptions PSPrinter.title Making these variables public (or at least get/settable) allows the print parameters to be set through other means without invoking the PrinterJob.printDialog() method. Cadence has already implemented and verified that this fix works. However, Cadence cannot distributed this fix because it is prohibited by the terms of the Java Binary license agreement.
11-06-2004

EVALUATION The answer is to use JDK1.4. APIs can only be changed in a major release, not a maintenance or update release. Making private variables public is considered an API change. This functionality is already integrated into JDK1.4 so I am marking this bug as integrated. ###@###.### 2002-03-01
01-03-2002