本文整理汇总了Java中java.awt.print.PrinterJob.printDialog方法的典型用法代码示例。如果您正苦于以下问题:Java PrinterJob.printDialog方法的具体用法?Java PrinterJob.printDialog怎么用?Java PrinterJob.printDialog使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.print.PrinterJob
的用法示例。
在下文中一共展示了PrinterJob.printDialog方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: actionPerformed
import java.awt.print.PrinterJob; //导入方法依赖的package包/类
/**
*
*/
public void actionPerformed(ActionEvent e) {
if (e.getSource() instanceof mxGraphComponent) {
mxGraphComponent graphComponent = (mxGraphComponent) e.getSource();
PrinterJob pj = PrinterJob.getPrinterJob();
if (pj.printDialog()) {
PageFormat pf = graphComponent.getPageFormat();
Paper paper = new Paper();
double margin = 36;
paper.setImageableArea(margin, margin, paper.getWidth() - margin * 2,
paper.getHeight() - margin * 2);
pf.setPaper(paper);
pj.setPrintable(graphComponent, pf);
try {
pj.print();
} catch (PrinterException e2) {
System.out.println(e2);
}
}
}
}
示例2: printTest
import java.awt.print.PrinterJob; //导入方法依赖的package包/类
private static void printTest() {
PrinterJob pj = PrinterJob.getPrinterJob();
PageFormat pf = pj.defaultPage();
Paper paper = new Paper();
double margin = 36; // half inch
paper.setImageableArea(margin, margin, paper.getWidth() - margin * 2,
paper.getHeight() - margin * 2);
pf.setPaper(paper);
pj.setPrintable(new PrintTestLexmarkIQ(), pf);
if (pj.printDialog()) {
try {
pj.print();
} catch (PrinterException e) {
System.out.println(e);
}
}
}
示例3: print
import java.awt.print.PrinterJob; //导入方法依赖的package包/类
void print(List<Paper> papers) {
PrinterJob job = PrinterJob.getPrinterJob();
myPapers = papers;
//out("SET PAPER: " + myPapers);
if (job == null) {
return;
}
job.setPrintable(this, Config.getDefault().getPageFormat());
try {
if (job.printDialog()) {
job.print();
}
}
catch (PrinterException e) {
printError(i18n(Printer.class, "ERR_Printer_Problem", e.getLocalizedMessage())); // NOI18N
}
myPapers = null;
}
示例4: createChartPrintJob
import java.awt.print.PrinterJob; //导入方法依赖的package包/类
/**
* Creates a print job for the chart.
*/
@Override
public void createChartPrintJob() {
PrinterJob job = PrinterJob.getPrinterJob();
PageFormat pf = job.defaultPage();
PageFormat pf2 = job.pageDialog(pf);
if (pf2 != pf) {
job.setPrintable(this, pf2);
if (job.printDialog()) {
try {
job.print();
} catch (PrinterException e) {
JOptionPane.showMessageDialog(this, e);
}
}
}
}
示例5: printWorksheetLevel
import java.awt.print.PrinterJob; //导入方法依赖的package包/类
public void printWorksheetLevel() {
PrinterJob print = PrinterJob.getPrinterJob();
PrintRequestAttributeSet set = new HashPrintRequestAttributeSet();
set.add(OrientationRequested.LANDSCAPE);
print.setPrintable(oscilloscope);
if(print.printDialog(set))
try { print.print(); }
catch(PrinterException e) {}
}
示例6: _printCrossPlatform
import java.awt.print.PrinterJob; //导入方法依赖的package包/类
/** Print using the cross platform dialog.
* FIXME: this dialog is slow and is often hidden
* behind other windows. However, it does honor
* the user's choice of portrait vs. landscape
*/
protected void _printCrossPlatform() {
// Build a set of attributes
PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
PrinterJob job = PrinterJob.getPrinterJob();
job.setPrintable(plot);
if (job.printDialog(aset)) {
try {
job.print(aset);
} catch (Exception ex) {
JOptionPane.showMessageDialog(this,
"Printing failed:\n" + ex.toString(),
"Print Error", JOptionPane.WARNING_MESSAGE);
}
}
}
示例7: _printNative
import java.awt.print.PrinterJob; //导入方法依赖的package包/类
/** Print using the native dialog.
* FIXME: This method does not seem to honor the user's
* choice of portrait vs. landscape.
*/
protected void _printNative() {
PrinterJob job = PrinterJob.getPrinterJob();
//PageFormat pageFormat = job.defaultPage();
//job.setPrintable(plot, pageFormat);
job.setPrintable(plot);
if (job.printDialog()) {
try {
// job.print() eventually
// calls PlotBox.print(Graphics, PageFormat)
job.print();
} catch (Exception ex) {
JOptionPane.showMessageDialog(this,
"Printing failed:\n" + ex.toString(),
"Print Error", JOptionPane.WARNING_MESSAGE);
}
}
}
示例8: printWithJavaPrintDialog
import java.awt.print.PrinterJob; //导入方法依赖的package包/类
private static void printWithJavaPrintDialog() {
final JTable table = createAuthorTable(50);
Printable printable = table.getPrintable(
JTable.PrintMode.NORMAL,
new MessageFormat("Author Table"),
new MessageFormat("Page - {0}"));
PrinterJob job = PrinterJob.getPrinterJob();
job.setPrintable(printable);
boolean printAccepted = job.printDialog();
if (printAccepted) {
try {
job.print();
closeFrame();
} catch (PrinterException e) {
throw new RuntimeException(e);
}
}
}
示例9: printDifferentRowHeight
import java.awt.print.PrinterJob; //导入方法依赖的package包/类
private static void printDifferentRowHeight() {
final JTable table = createAuthorTable(50);
table.setRowHeight(15, table.getRowHeight(15)+10);
Printable printable = table.getPrintable(
JTable.PrintMode.NORMAL,
new MessageFormat("Author Table"),
new MessageFormat("Page - {0}"));
PrinterJob job = PrinterJob.getPrinterJob();
job.setPrintable(printable);
boolean printAccepted = job.printDialog();
if (printAccepted) {
try {
job.print();
closeFrame();
} catch (PrinterException e) {
throw new RuntimeException(e);
}
}
}
示例10: createChartPrintJob
import java.awt.print.PrinterJob; //导入方法依赖的package包/类
/**
* Creates a print job for the chart.
*/
public void createChartPrintJob() {
PrinterJob job = PrinterJob.getPrinterJob();
PageFormat pf = job.defaultPage();
PageFormat pf2 = job.pageDialog(pf);
if (pf2 != pf) {
job.setPrintable(this, pf2);
if (job.printDialog()) {
try {
job.print();
}
catch (PrinterException e) {
JOptionPane.showMessageDialog(this, e);
}
}
}
}
示例11: createChartPrintJob
import java.awt.print.PrinterJob; //导入方法依赖的package包/类
/**
* Creates a print job for the chart.
*/
public void createChartPrintJob() {
//FIXME try to replace swing print stuff by swt
PrinterJob job = PrinterJob.getPrinterJob();
PageFormat pf = job.defaultPage();
PageFormat pf2 = job.pageDialog(pf);
if (pf2 != pf) {
job.setPrintable(this, pf2);
if (job.printDialog()) {
try {
job.print();
}
catch (PrinterException e) {
MessageBox messageBox = new MessageBox(
canvas.getShell(), SWT.OK | SWT.ICON_ERROR );
messageBox.setMessage( e.getMessage() );
messageBox.open();
}
}
}
}
示例12: printOneRowWithJavaPrintDialog
import java.awt.print.PrinterJob; //导入方法依赖的package包/类
private static void printOneRowWithJavaPrintDialog() {
final JTable table = createAuthorTable(1);
Printable printable = table.getPrintable(
JTable.PrintMode.NORMAL,
new MessageFormat("Author Table"),
new MessageFormat("Page - {0}"));
PrinterJob job = PrinterJob.getPrinterJob();
job.setPrintable(printable);
boolean printAccepted = job.printDialog();
if (printAccepted) {
try {
job.print();
closeFrame();
} catch (PrinterException e) {
throw new RuntimeException(e);
}
}
}
示例13: PolylinePrintingTest
import java.awt.print.PrinterJob; //导入方法依赖的package包/类
public PolylinePrintingTest() throws PrinterException {
PrinterJob job = PrinterJob.getPrinterJob();
PageFormat pf = job.defaultPage();
Paper p = pf.getPaper();
p.setImageableArea(0,0,p.getWidth(), p.getHeight());
pf.setPaper(p);
job.setPrintable(this, pf);
if (job.printDialog()) {
job.print();
}
}
示例14: print
import java.awt.print.PrinterJob; //导入方法依赖的package包/类
public void print() {
PrinterJob printJob = PrinterJob.getPrinterJob();
printJob.setPrintable((g, format, page) -> {
if (page > 0) {
return Printable.NO_SUCH_PAGE;
}
// get the bounds of the component
Rectangle drawingArea = getDrawingArea();
double cHeight = drawingArea.getSize().getHeight();
double cWidth = drawingArea.getSize().getWidth();
// get the bounds of the printable area
double pHeight = format.getImageableHeight();
double pWidth = format.getImageableWidth();
double pXStart = format.getImageableX();
double pYStart = format.getImageableY();
//find ratio
double xRatio = pWidth / cWidth;
double yRatio = pHeight / cHeight;
Graphics2D g2d = (Graphics2D) g;
//translate and scale accordingly
g2d.translate(pXStart, pYStart);
g2d.scale(xRatio, yRatio);
paintDrawing(g2d, drawingArea.x, drawingArea.y);
return Printable.PAGE_EXISTS;
});
if (printJob.printDialog()) {
try {
printJob.print();
} catch (PrinterException e) {
UIUtility.error(e.getMessage());
}
}
}
示例15: printWorksheet
import java.awt.print.PrinterJob; //导入方法依赖的package包/类
public void printWorksheet() {
PrinterJob print = PrinterJob.getPrinterJob();
print.setPrintable(desktop.getSelectedFrame());
if(print.printDialog(new HashPrintRequestAttributeSet()))
try { print.print(); }
catch(PrinterException e) {}
}