JDK-4784285 : Focus of Main Application lost after closing awt.print.PrinterJob.printDialog()
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 1.4.0
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_2000
  • CPU: x86
  • Submitted: 2002-11-25
  • Updated: 2002-12-13
  • Resolved: 2002-12-13
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.2 b11Fixed
Related Reports
Relates :  
Relates :  
Description

Name: jl125535			Date: 11/25/2002


FULL PRODUCT VERSION :
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 2000 professional

A DESCRIPTION OF THE PROBLEM :
After closing print dialog (either clicking OK or Cancel),
the main application loses the focus.  Other application in
the machine gains the focus, and hide the java application.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1.  Run the code attached
2.  Closing the print dialog either clicking OK or cancel
3.  Note that the main application loses the focus.  Other
application in the machine gains the focus, and hide the
java application.

EXPECTED VERSUS ACTUAL BEHAVIOR :
The java application should still be the one on focus

This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.awt.*;
import java.awt.print.*;
import javax.swing.*;

class Test2 {

	public static void main(String[] args) {
		JFrame myFrame = new JFrame("Test");
		myFrame.setSize(new Dimension(200,200));
		myFrame.setVisible(true);

		//Users supplied code
		PrinterJob prnJob = PrinterJob.getPrinterJob();
         if (prnJob.printDialog())
         {  try
            {  prnJob.print();
            }
            catch (PrinterException exception)
            {
            }
         }

	}

}

---------- END SOURCE ----------

CUSTOMER WORKAROUND :
use requestfocus()
(Review ID: 145492) 
======================================================================

Name: jl125535			Date: 11/25/2002


When the Print dialog is dismissed using either OK or Cancel, the 
application JFrame drops to one window from the top in the windows 
application z-order.
(Review ID: 145677)
======================================================================

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: mantis-beta FIXED IN: mantis-beta INTEGRATED IN: mantis-b11 mantis-beta
24-08-2004

SUGGESTED FIX Name: osR10079 Date: 11/28/2002 ------- awt_PrintJob.cpp ------- *** /tmp/dV0aqTf Thu Nov 28 13:34:30 2002 --- awt_PrintJob.cpp Thu Nov 28 13:26:05 2002 *************** *** 429,434 **** --- 429,435 ---- AwtDialog::ModalDisable(NULL); BOOL ret = AwtCommDialog::PageSetupDlg(&setup); AwtDialog::ModalEnable(NULL); + AwtDialog::ModalNextWindowToFront(NULL); if (ret) { *************** *** 565,570 **** --- 566,572 ---- AwtDialog::ModalDisable(NULL); BOOL ret = AwtCommDialog::PrintDlg(&job); AwtDialog::ModalEnable(NULL); + AwtDialog::ModalNextWindowToFront(NULL); if (ret) { /* Drivers indicate support for multiple copies via the DEVMODE ###@###.### 2002-11-28 ======================================================================
28-11-2002

EVALUATION Focus issues are part of AWT. ###@###.### 2002-11-25 Name: osR10079 Date: 11/25/2002 In 1.4.2 test's behavior is a little bit different from 1.4 one. After the test starts Frame is active and print dialog is under it (in 1.4 dialog is active). If we activate dialog and close it frame becomes active. When i add pause after frame's showing, dialog becomes active after test starts. After dialog's closeing frame is activated. I think that the problem is timing issue because we show frame and dialog on different threads (native frame will be shown on toolkit's thread, dialog on main thread). Thus it's undefined which native window will be active when dialog is shown. But print dialog is modeless, thus after its closeing will be activated window which was active before last dialog activation. So, if we show print dialog when any non-java window is active this window will be activated after dialog's closeing. ###@###.### 2002-11-26 ====================================================================== Name: osR10079 Date: 11/28/2002 Print dialog is modeless because of 4785920(Regression of 4273333 in hopper) After fixing it, behavior desciobed in this bug restored. Looks like it is a problem in initial fix for 4273333, which made print dialog modal, but not activate any java-window after dialog closing. The same problem exists for page setup dialog. ###@###.### 2002-11-28 ======================================================================
28-11-2002