[macosx] Java 7 print dialog creates a new window on app-switch.

Abhinay Reddyreddy Abhinay.Reddyreddy at mathworks.com
Tue Mar 12 11:41:17 PDT 2013


I have noticed a bug in Java 7 print dialog on Mac. I have reported it to bugs.sun.com<http://bugs.sun.com> but did not receive any response.
Could someone confirm if this bug has been noticed and fixed or if there is any workaround for it.

Thanks,
Abhinay.

Issue: An extra window is created at the top-left corner of the screen, if a user switches the app while it is showing a native print dialog.

Steps to reproduce:
Run the attached code
click print button
when the native print dialog shows up, switch to a different app using Cmd+Tab or mouse
switch back to the java app with print dialog
notice a new window is created at the top right corner of the screen.

java -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)


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;
import java.awt.print.PrinterException;

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();
                if(printJob.printDialog(attributes))
                {
                try {
                printJob.print();
                } catch (PrinterException pe) {
                }
                }

            }
        });
        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);
            }
        });

    }
}



More information about the macosx-port-dev mailing list