Win a copy of Murach's MySQL this week in the JDBC and Relational Databases forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Print dialog

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i have add a menu item print in the File Menu and when i click the print menu item the print dialog should open as it is opening in MsWord i am using the following code for the dialog to pop up , but it does not pop up, if anyone know how to resolve it, it would be great helpfull to me.

The code that i used is
FileDialog fileChooser = new FileDialog(shell, SWT.OPEN);
String fileName = fileChooser.open();


if (fileName == null) { return; }

// Load the image
ImageLoader loader = new ImageLoader();
ImageData[] imageData = loader.load(fileName);
PrinterData printerData = null;
if (imageData.length > 0) {//
// Show the Choose Printer dialog
PrintDialog dialog = new PrintDialog(shell, SWT.CLOSE);
try{
printerData = dialog.open();

}catch(Exception e){
e.printStackTrace();
}

if (printerData != null) {
// Create the printer object
Printer printer = new Printer(printerData);

// Calculate the scale factor between the screen resolution and printer
// resolution in order to correctly size the image for the printer
Point screenDPI = display.getDPI();
Point printerDPI = printer.getDPI();
int scaleFactor = printerDPI.x / screenDPI.x;
// Determine the bounds of the entire area of the printer
Rectangle trim = printer.computeTrim(0, 0, 0, 0);
// Start the print job
if (printer.startJob(fileName)) {
if (printer.startPage()) {
GC gc = new GC(printer);
Image printerImage = new Image(printer, imageData[0]);

// Draw the image
gc.drawImage(printerImage, 0, 0, imageData[0].width,
imageData[0].height, -trim.x, -trim.y,
scaleFactor * imageData[0].width,
scaleFactor * imageData[0].height);

// Clean up
printerImage.dispose();
gc.dispose();
printer.endPage();
}
}
// End the job and dispose the printer
printer.endJob();
printer.dispose();
} else {
System.out.println("No data to print");
}

KINDLY HELP ME TO KNOW IF ANY THING THAT NEEDED TO BE CHANGED TO BRING THE PRINTER DIALOG BOX.
 
Marshal
Posts: 79006
375
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Complicated, that is. Get a copy of a book I quote often, C Horstmann and G Cornell, Core Java 2 (vol II advanced features), 7th Edition, Santa Clara CA, Sun Microsystems Press (Prentice-Hall), and read pages 539 to 575.
Once you get through their simpler examples it becomes a lot easier.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic