-
Bug
-
Resolution: Fixed
-
P4
-
1.2.2, 1.4.1
-
b43
-
x86
-
windows_nt, windows_xp
Name: rmT116609 Date: 10/01/2002
FULL PRODUCT VERSION :
java version "1.4.1"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1-b21)
Java HotSpot(TM) Client VM (build 1.4.1-b21, mixed mode)
*****************************************
*** But also present under the following:
*****************************************
java version "1.2.2"
Classic VM (build JDK-1.2.2-W, native threads, symcjit)
java version "1.4.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-b92)
Java HotSpot(TM) Client VM (build 1.4.0-b92, mixed mode)
FULL OPERATING SYSTEM VERSION :
Windows NT v4.00.1381, Windows 2000
A DESCRIPTION OF THE PROBLEM :
The dialog displayed by using PrinterJob.pageDialog() under
NT 4.0 has a "Printer..." button which allows the user to
change the destination printer.
However, modification of the destination printer using the
resulting dialog has no effect on where the printout
appears - the default printer is always used.
If the PrinterJob.printDialog() is used to select the
printer ___in addition to the PrinterJob.pageDialog()___
then the correct printer is used.
If this unintuitive behaviour is intended (as implied by
4531834 RFE et al) then at the very least the Printer...
button should be removed from the page dialog (as seemed to
be the case in java 1.3.1).
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Ensure you have access to at least 2 printers. Note
which one is the default printer.
2. Create a class that implements Printable.
3. Add the following code to the class:
PrinterJob job = PrinterJob.getPrinterJob();
PageFormat originalPageFormat = job.defaultPage();
pageFormat = job.pageDialog(originalPageFormat);
if (originalPageFormat == pageFormat) return;
job.setPrintable(this, pageFormat);
job.print();
4. Execute the code above, and when the page dialog appears
press the Printer... button and select any printer except
the default. Select Ok twice to execute the print job.
EXPECTED VERSUS ACTUAL BEHAVIOR :
At step 4, I expected printout at the selected printer.
The actual behaviour was that the printout appeared at the
default printer.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.awt.print.PrinterJob;
import java.awt.print.PageFormat;
import java.awt.print.Printable;
import java.awt.print.PrinterException;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
public class PrintBug2 implements Printable
{
public PrintBug2()
{
try
{
pageDialogExample();
}
catch(Exception e)
{e.printStackTrace(System.err);}
}
// This example just displays the page dialog - you cannot change
// the printer (press the "Printer..." button and choose one if you like).
public void pageDialogExample() throws PrinterException
{
PrinterJob job = PrinterJob.getPrinterJob();
PageFormat originalPageFormat = job.defaultPage();
PageFormat pageFormat = job.pageDialog(originalPageFormat);
if(originalPageFormat == pageFormat) return;
job.setPrintable(this,pageFormat);
job.print();
}
public static void main(String[] args)
{
PrintBug2 example = new PrintBug2();
}
public int print(Graphics g, PageFormat pageFormat, int pageIndex)
{
final int boxWidth = 100;
final int boxHeight = 100;
final Rectangle rect = new Rectangle(0,0,boxWidth,boxHeight);
final double pageH = pageFormat.getImageableHeight();
final double pageW = pageFormat.getImageableWidth();
if (pageIndex > 0) return (NO_SUCH_PAGE);
final Graphics2D g2d = (Graphics2D)g;
// Move the (x,y) origin to account for the left-hand and top margins
g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
// Draw the page bounding box
g2d.drawRect(0,0,(int)pageW,(int)pageH);
// Select the smaller scaling factor so that the figure
// fits on the page in both dimensions
final double scale = Math.min( (pageW/boxWidth), (pageH/boxHeight) );
if(scale < 1.0) g2d.scale(scale, scale);
// Paint the scaled component on the printer
g2d.fillRect(rect.x, rect.y, rect.width, rect.height);
return(PAGE_EXISTS);
}
}
---------- END SOURCE ----------
CUSTOMER WORKAROUND :
Use the printDialog() method to set the destination printer
in addition to the pageDialog() method to set the page
layout.
(Review ID: 165030)
======================================================================
Name: rmT116609 Date: 02/12/2003
DESCRIPTION OF THE PROBLEM :
The application always use the default printer. I try to change the printer from the dialog that appears when I press the ?Printer??button in the PageDialog (from
PrinterJob), but the application use the default printer anyway.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1.Create a PrinterJob and show the PageDialog
2.Change printer by pressing the "Printer..." button in the dialog.
3.Print.
EXPECTED VERSUS ACTUAL BEHAVIOR :
Expected: The application should use the chosen printer.
Actual Results: The application use the default printer.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
/*
* Application1.java
*/
import javax.swing.UIManager;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.print.*;
public class Application1 {
boolean packFrame = false;
/**Construct the application*/
public Application1 () {
Frame1 frame = new Frame1 ();
frame.validate ();
frame.setVisible (true);
}
/**Main method*/
public static void main (String[] args) {
new Application1 ();
}
public class Frame1 extends JFrame {
JPanel contentPane;
BorderLayout borderLayout1 = new BorderLayout ();
JPanel jPanel1 = new JPanel ();
JPanel jPanel2 = new JPanel ();
JButton jButton1 = new JButton ();
JLabel jLabel1 = new JLabel ();
/**Construct the frame*/
public Frame1 () {
enableEvents (AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit ();
}
catch (Exception e) {
e.printStackTrace ();
}
}
/**Component initialization*/
private void jbInit () throws Exception {
contentPane = (JPanel) this.getContentPane ();
contentPane.setLayout (borderLayout1);
this.setSize (new Dimension (400, 300));
this.setTitle ("Frame Title");
jButton1.setText ("jButton1");
jButton1.addActionListener (new java.awt.event.ActionListener () {
public void actionPerformed (ActionEvent e) {
jButton1_actionPerformed (e);
}
});
jLabel1.setText ("Test area");
contentPane.add (jPanel1, BorderLayout.CENTER);
jPanel1.add (jLabel1, null);
contentPane.add (jPanel2, BorderLayout.SOUTH);
jPanel2.add (jButton1, null);
}
protected void processWindowEvent (WindowEvent e) {
super.processWindowEvent (e);
if (e.getID () == WindowEvent.WINDOW_CLOSING) {
System.exit (0);
}
}
void jButton1_actionPerformed (ActionEvent e) {
try {
PrinterJob job = PrinterJob.getPrinterJob ();
PageFormat pageformat = job.defaultPage ();
pageformat = job.pageDialog (pageformat);
Book bk = new Book ();
bk.append (new PaintPanel (this), pageformat);
job.setPageable (bk);
job.print ();
} catch (Exception e2) {
e2.printStackTrace();
}
}
private class PaintPanel implements Printable {
private JFrame frame;
public PaintPanel (JFrame frame) {
this.frame = frame;
}
public int print (Graphics g, PageFormat pf, int pageIndex)
throws PrinterException {
g.translate ((int) pf.getImageableX (),
(int) pf.getImageableY ());
frame.paint (g);
return Printable.PAGE_EXISTS;
}
}
}
}
---------- END SOURCE ----------
(Review ID: 181115)
======================================================================
- relates to
-
JDK-6180457 REGRESSION: getPrintService() return wrong printer sel. in pageDialog
-
- Resolved
-