Printing in Sandbox
Jessica Finley
jfinley at tech4learning.com
Wed Mar 20 13:30:05 PDT 2013
Hiya,
It appears that trying to print, even using the standard native dialog, causes a sandbox violation - in both JDK 7 and JDK 8. Below is a sample class which needs to be bundled into a sandboxed app to show the problem (kudos to Abhinay as this is just a slight modification of his print code submitted a few days ago).
The violation occurs after you dismiss the native print dialog by pressing its Print button.
I've also noticed that if you then let the app run untouched while, for example, you type up an email, it continues to throw sandbox violations of the same nature.
Is there something I'm missing? I do have the com.apple.security.print entitlement set to true… This seems like a nasty bug…
-Jess
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.print.PrinterException;
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 javax.swing.SwingUtilities;
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) {
PrinterJob printJob = PrinterJob.getPrinterJob();
if(printJob.printDialog())
{
//don't even need to actually print,
//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() {
public void run() {
PrintDialogTestCase window = new PrintDialogTestCase();
window.setVisible(true);
}
});
}
}
More information about the macosx-port-dev
mailing list