United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-4775862 : Cross-platform PrinterJob.printDialog gets hidden by main application window

Details
Type:
Bug
Submit Date:
2002-11-08
Status:
Closed
Updated Date:
2004-02-16
Project Name:
JDK
Resolved Date:
2003-11-04
Component:
client-libs
OS:
windows_2000
Sub-Component:
2d
CPU:
x86
Priority:
P4
Resolution:
Fixed
Affected Versions:
1.4.1,1.4.2
Fixed Versions:
1.4.2_04 (04)

Related Reports
Backport:
Duplicate:
Relates:
Relates:

Sub Tasks

Description

Name: jk109818			Date: 11/07/2002


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 :
Microsoft 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) 
======================================================================

                                    

Comments
SUGGESTED FIX

1.5 has a new API
java.awt.Window.setAlwaysOnTop(boolean alwaysOnTop) throws SecurityException

We should call this API (in a doPrivileged block) on the print dialog
prior to showing it.

###@###.### 2003-10-16
===========================
                                     
2003-10-16
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.

###@###.### 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.

###@###.### 2003-10-22
=====================================

Additional fix for this is covered by bug 4969336
###@###.### 2003-12-17
                                     
2003-10-22
CONVERTED DATA

BugTraq+ Release Management Values

COMMIT TO FIX:
1.4.2_04
generic
tiger-beta

FIXED IN:
1.4.2_04
tiger-beta

INTEGRATED IN:
1.4.2_04
tiger-b28
tiger-beta

VERIFIED IN:
1.4.2_04


                                     
2004-06-14



Hardware and Software, Engineered to Work Together