Select some options programmatically before displaying the dialog : PrintDialog « SWT « Java Tutorial






import org.eclipse.swt.printing.PrintDialog;
import org.eclipse.swt.printing.PrinterData;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class MainClass {
  public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);

    PrintDialog dlg = new PrintDialog(shell);
    
    dlg.setScope(PrinterData.SELECTION);
    
    PrinterData printerData = dlg.open();
    if (printerData != null) {

      System.out.println(printerData.printToFile);

      // Printer printer = new Printer(printerData);
      // Use printer . . .
      // printer.dispose();
    }

    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) {
        display.sleep();
      }
    }
    display.dispose();
  }
}








17.111.PrintDialog
17.111.1.PrintDialog.open() returns a PrinterData object.
17.111.2.Select some options programmatically before displaying the dialog