Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 4775862
Votes 9
Synopsis Cross-platform PrinterJob.printDialog gets hidden by main application window
Category java:classes_2d
Reported Against 1.4.1 , 1.4.2
Release Fixed 1.4.2_04, 1.5(tiger-b28) (Bug ID:2060922)
State 10-Fix Delivered, Verified, bug
Priority: 4-Low
Related Bugs 4916664 , 4969336 , 4940645
Submit Date 08-NOV-2002
Description




FULL PRODUCT VERSION :
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0_02-b02)
Java HotSpot(TM) Client VM (build 1.4.0_02-b02, mixed mode)

AND

java version "1.4.1_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_01-b01)
Java HotSpot(TM) Client VM (build 1.4.1_01-b01, mixed mode)

FULL OPERATING SYSTEM VERSION :
 customer  Windows 2000 [Version 5.00.2195]

A DESCRIPTION OF THE PROBLEM :
The PrinterJob.printDialog class does not provide a method
for constructing a cross-platform Print dialog that accepts
an "owner" Dialog or Frame, in contrast to the constructors
provided by the Swing JDialog class which do allow the
specification of an owner.  The result is that the Print
dialog can be hidden inadvertently behind its main
application window and users think they've "lost" the
dialog.  Since the Print dialog is modal, it isn't even
possible to select the main application window for the
purpose of moving it aside so as to expose the dialog
behind it.



STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Compile and run the attached program.  The main
application window will appear.

2. Click on the Print button.  The cross-platform print
dialog will appear, centered over the application window.

2. Open, or click on, another application window on the
desktop (for example, Internet Explorer or Windows
Explorer).

3. From the Windows taskbar, click on the coffee-cup icon
for the sample application started in step 1.



EXPECTED VERSUS ACTUAL BEHAVIOR :
I would expect the Print dialog to appear on top of the
main application frame.  Instead the main application
window appears on top of, and hides, the Print dialog, and
since the Print dialog is modal, it isn't even possible to
select the main application window for the purpose of
moving it aside so as to expose the dialog.

I would like, instead, for the Print dialog to appear on
top of the main application window when the application
window is brought to the front.  This is the behavior that
occurs for Swing JDialogs that are instantiated using the
constructors that take an "owner" Dialog or Frame.


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.print.Printable;
import java.awt.print.PrinterException;
import java.awt.print.PrinterJob;
import javax.print.attribute.HashPrintRequestAttributeSet;
import javax.print.attribute.PrintRequestAttributeSet;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.SwingConstants;

public class PrinterJobDialogBugDemo extends JFrame implements Printable {

  public static void main(String[] args) {
    new PrinterJobDialogBugDemo();
  }

  private PrinterJobDialogBugDemo() {
    super("Printer Job Dialog Bug Demo");

    setDefaultCloseOperation(EXIT_ON_CLOSE);
    setSize(700,700);
    
    JButton btnPrint = new JButton("Print...");
    btnPrint.addActionListener(new ActionListener()
      {
        public void actionPerformed(ActionEvent ae) {
          showPrintDialog();
        }
      });

    Container contentPane = getContentPane();
    contentPane.add(
      new JLabel("<html>This is the main Application Window. " +
                 "To demonstrate the problem:" +
                 "<ol>" +
                 "<li>Click the Print button at the bottom of this window. " +
                 "The Print dialog will appear." +
                 "<li>Select another application window." +
                 "<li>On the Windows taskbar, click the coffee-cup icon for " +
                 "this demo application.  This brings this window to the " +
                 "front but the Print dialog remains hidden. " +
                 "Since this window " +
                 "is no longer selectable, it can't be moved aside to expose " +
                 "the Print dialog that is now behind it." +
                 "</ol>",
                 SwingConstants.CENTER),
      BorderLayout.NORTH);
    contentPane.add(btnPrint, BorderLayout.SOUTH);
    setVisible(true);
  }

  private void showPrintDialog() {
    PrinterJob printJob = PrinterJob.getPrinterJob();
    printJob.setPrintable(this);
    PrintRequestAttributeSet printRequestAttrSet =
      new HashPrintRequestAttributeSet();
    printJob.printDialog(printRequestAttrSet);
  }

  public int print(java.awt.Graphics g, java.awt.print.PageFormat pageFormat,
int pageIndex) {
    if (pageIndex == 0) {
      return(PAGE_EXISTS);
    } else {
      return(NO_SUCH_PAGE);
    }
  }
}

---------- END SOURCE ----------
(Review ID: 166556) 
======================================================================
Work Around
N/A
Evaluation
There is a proposal for a new API : 4632143: window/frame/dialog always on top
which could be called by the printing implementation to ensure that the
print dialog remains above other windows.

  xxxxx@xxxxx   2003-06-04
============================

Fixed using setAlwaysOnTop but as of this writing, there is an existing bug, 4940645 which hinders us from verifying if the fix works.  Based on Bino's evaluation of the way we call setAlwaysOnTop, he said that it should work.  Will not be marking as fixed until that bug has been fixed.

  xxxxx@xxxxx   2003-10-22
=====================================

Additional fix for this is covered by bug 4969336
  xxxxx@xxxxx   2003-12-17
Comments
  
  Include a link with my name & email   

Submitted On 21-NOV-2002
bernie01
This looks like a platform specific bug not an enhancement.
On Windows 98 with JDK 1.4.1, the behavior appears to be
correct: The dialog blocks.  After switching to another
maximised application, only the print dialog with its coffee
cup icon is selectable on the task bar (no application
icon). The application main window returns after the dialog
is cancelled.
In any case, I would like to see the icon of the application
and not the coffee cup on the task bar and the dialog
centered on the screen. That would of course be an
enhancement because, as the documentation writes,
printDialog(PrintRequestAttributeSet printRequestAttrSet) is
a convenience method.


Submitted On 28-JAN-2003
ethanleet
I agree.  We need more controll over the printDialog.
PrinterJob should ahve a method createDialog() or createPanel
().
I too amd losing dialogs behind other frame, dialogs, terminals, 
etc.  We need more control over the dialog, not all window 
managers will allow to acces to the lost window. 


Submitted On 03-SEP-2003
lschoenberg
Please note that this request is closely related to 4916664, 
which I submitted at about the same time as I submitted this 
request.


Submitted On 15-OCT-2003
jay.johansen
I don't think the answer is another call. As in, When would 
you NOT want the print dialog to appear on top when it is 
invoked? The printDialog() function should automatically do 
whatever it needs to do to make this window be on top.


Submitted On 16-OCT-2003
philr
>I don't think the answer is another call.
Agreed and the proposal is NOT that you (the developer) make
another call. The proposal is that the JRE *implementation* make
this call for you on the dialog. So it'll just work.


Submitted On 15-FEB-2004
bikestain
This is still reproducible in 1.4.2_3.


Submitted On 29-NOV-2007
We DO need another call, e.g. if an application wants to support auto-logoff feature, it HAS to be able to dispose the printdialog.

That is not possible in the current solution.



PLEASE NOTE: JDK6 is formerly known as Project Mustang