Trouble with Print Dialog Focus In Java

338 views Asked by At

I have a JFrame and it opens java Print Dialog.Like below

 PrinterJob pj = PrinterJob.getPrinterJob();
  if (pj.printDialog()) {
      //Print
    }

The problem is that my JFrame has the setAlwaysOnTop(true) attribute and Print dialog is opened in the background of the JFrame. To solve this problem I want to follow such a way

Before opening Printdialog, i will set setAlwaysOnTop(false) After opening print dialog i will set setAlwaysOnTop(true) again.

But how to know my print dilaog is opened ?

Because pj.printDialog() is waiting.

How to get the print dilaog opened event ?

1

There are 1 answers

0
engtuncay On

You can use printrequestAttributeSet object to brint printer dialog on top. For example;

PrintRequestAttributeSet set = new HashPrintRequestAttributeSet();
set.add(OrientationRequested.LANDSCAPE);
set.add(new sun.print.DialogOnTop());

Then , use

pj.printDialog(set)