JDK-8013543 : Extra window created when app-switch happens using Cmd+Tab or Mouse
  • Type: Bug
  • Component: client-libs
  • Sub-Component: 2d
  • Affected Version: 7u13
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: os_x
  • Submitted: 2013-04-04
  • Updated: 2014-11-17
  • Resolved: 2013-05-14
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
java version  " 1.7.0_13 " 
Java(TM) SE Runtime Environment (build 1.7.0_13-b20)
Java HotSpot(TM) 64-Bit Server VM (build 23.7-b01, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Mac OS X 10.7.5

EXTRA RELEVANT SYSTEM CONFIGURATION :
Processor  2.5 GHz Intel Core i5
Memory  8 GB 1333 MHz DDR3
Graphics  AMD Radeon HD 6630M 256 MB
Software  Mac OS X Lion 10.7.5 (11G63)

A DESCRIPTION OF THE PROBLEM :
A new window is created when the user does an app-switch while the native print dialog is showing in Java app.

REGRESSION.  Last worked in version 6u31

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
compile and run the attached test case.
In the UI click the  " Print Dialog "  button. This will show the native print dialog.
now switch to a different app using cmd+Tab or mouse.
switch back to the app.
notice the print dialog did not get focus, instead a new window is created at the top left corner of the screen.
This window does not disappear after the print dialog is closed.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Print dialog gets focus
ACTUAL -
A new window is created at the top-left corner of the screen, which gets the focus. Print dialog is not in focus.The new window will stay even after the print dialog is closed.

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------

import javax.swing.SwingUtilities;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.print.PrinterJob;
import javax.print.attribute.HashPrintRequestAttributeSet;
import javax.print.attribute.PrintRequestAttributeSet;
import javax.print.attribute.standard.DialogTypeSelection;
import javax.swing.JButton;
import javax.swing.JFrame;

public class PrintDialogTestCase extends JFrame {

public PrintDialogTestCase() {
        this.setTitle( " Example " );
        this.setSize(200, 100);
        this.setLocationRelativeTo(null);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                
        this.setLayout(new FlowLayout());
        JButton printDialogButton = new JButton( " Print Dialog " );
        printDialogButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent event) {
                final PrintRequestAttributeSet attributes = new HashPrintRequestAttributeSet();
                attributes.add(DialogTypeSelection.NATIVE);
                PrinterJob printJob = PrinterJob.getPrinterJob();
                printJob.printDialog(attributes);

            }
        });
        this.add(printDialogButton);
        
        JButton exitButton = new JButton( " Exit " );
        exitButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent event) {
                System.exit(0);
            }
        });
        this.add(exitButton);
    }

    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                PrintDialogTestCase window = new PrintDialogTestCase();
                window.setVisible(true);
            }
        });

    }
}

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

CUSTOMER SUBMITTED WORKAROUND :
None, if you want to use the native print dialogs in your app. Windows.getWindows does not list this new window.
Comments
The problem is already fixed in JDK8. The fix will be backported to the JDK7 soon.
14-05-2013