站内搜索: 请输入搜索关键词
当前页面: 在线文档首页 > Java Tutorial 5.0 英文版

Displaying a Page Setup Dialog - Java Tutorial 5.0 英文版

The JavaTM Tutorial
Previous Page Lesson Contents Next Page Start of Tutorial > Start of Trail > Start of Lesson Search
Feedback Form

Trail: 2D Graphics
Lesson: Printing

Displaying a Page Setup Dialog

You can allow the user to specify page characteristics, such as the paper size and orientation, by displaying a Page Setup dialog. The page information is stored in a PageFormat object. Like the Print dialog, the Page Setup dialog is displayed by calling a method on the PrinterJob object, pageDialog.

The Page Setup dialog is initialized by using the PageFormat passed to the pageDialog method. If the user clicks the OK button in the dialog, the PageFormat is cloned, altered to reflect the user's selections, and then returned. If the user cancels the dialog, pageDialog returns the original, unaltered PageFormat.

ShapesPrint could easily be modified to display a Page Setup dialog by adding a call to pageDialog after you get the PrinterJob.

// Get a PrinterJob
PrinterJob job = PrinterJob.getPrinterJob();
// Ask user for page format (e.g., portrait/landscape)
PageFormat pf = job.pageDialog(job.defaultPage());

Previous Page Lesson Contents Next Page Start of Tutorial > Start of Trail > Start of Lesson Search
Feedback Form

Copyright 1995-2005 Sun Microsystems, Inc. All rights reserved.