当前位置: 首页>>代码示例>>Java>>正文


Java PrinterJob.setPrintable方法代码示例

本文整理汇总了Java中java.awt.print.PrinterJob.setPrintable方法的典型用法代码示例。如果您正苦于以下问题:Java PrinterJob.setPrintable方法的具体用法?Java PrinterJob.setPrintable怎么用?Java PrinterJob.setPrintable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.awt.print.PrinterJob的用法示例。


在下文中一共展示了PrinterJob.setPrintable方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: thirdPartyPrintLogic

import java.awt.print.PrinterJob; //导入方法依赖的package包/类
static void thirdPartyPrintLogic(String printerName) throws Exception {
    PrinterJob printerjob = PrinterJob.getPrinterJob();
    printerjob.setCopies(2);
    printerjob.setJobName("myJobName");
    printerjob.setPrintable(new DummyPrintable());
    for (PrintService printService : PrinterJob.lookupPrintServices()) {
        System.out.println("check printer name of service " + printService);
        if (printerName.equals(printService.getName())) {
            System.out.println("correct printer service do print...");
            printerjob.setPrintService(printService);
            printerjob.print();
            break;
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:16,代码来源:DummyPrintTest.java

示例2: 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);
      }
    }
  }
}
 
开发者ID:ModelWriter,项目名称:Tarski,代码行数:26,代码来源:EditorActions.java

示例3: 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);
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:20,代码来源:PrintTestLexmarkIQ.java

示例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);
			}
		}
	}

}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:23,代码来源:AbstractChartPanel.java

示例5: doTest

import java.awt.print.PrinterJob; //导入方法依赖的package包/类
private static void doTest() {
    PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
    aset.add(Chromaticity.MONOCHROME);

    MediaSize isoA5Size = MediaSize.getMediaSizeForName(MediaSizeName.ISO_A5);
    float[] size = isoA5Size.getSize(Size2DSyntax.INCH);
    Paper paper = new Paper();
    paper.setSize(size[0] * 72.0, size[1] * 72.0);
    paper.setImageableArea(0.0, 0.0, size[0] * 72.0, size[1] * 72.0);
    PageFormat pf = new PageFormat();
    pf.setPaper(paper);

    PrinterJob job = PrinterJob.getPrinterJob();
    job.setPrintable(new WrongPaperPrintingTest(), job.validatePage(pf));
    if (job.printDialog()) {
        try {
            job.print(aset);
        } catch (PrinterException pe) {
            throw new RuntimeException(pe);
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:23,代码来源:WrongPaperPrintingTest.java

示例6: _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);
        }
    }
}
 
开发者ID:OpenDA-Association,项目名称:OpenDA,代码行数:23,代码来源:PlotFrame.java

示例7: 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);
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:ImageableAreaTest.java

示例8: 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);
			}
		}
	}
}
 
开发者ID:ModelWriter,项目名称:Tarski,代码行数:33,代码来源:EditorActions.java

示例9: printWithJavaPrintDialog

import java.awt.print.PrinterJob; //导入方法依赖的package包/类
private static void printWithJavaPrintDialog() {
    final JTable table = createAuthorTable(42);
    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);
        }
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:21,代码来源:ImageableAreaTest.java

示例10: 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);
        }
    }

}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:23,代码来源:ImageableAreaTest.java

示例11: printTest

import java.awt.print.PrinterJob; //导入方法依赖的package包/类
private static void printTest() {
    PrinterJob job = PrinterJob.getPrinterJob();
    if (job.getPrintService() == null) {
        System.out.println("No printers. Test cannot continue");
        return;
    }
    job.setPrintable(new DlgAttrsBug());
    PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
    aset.add(new Copies(5));
    aset.add(new PageRanges(3,4));
    aset.add(DialogTypeSelection.NATIVE);
    job.printDialog(aset);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:14,代码来源:DlgAttrsBug.java

示例12: 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());
    }
  }
}
 
开发者ID:onprom,项目名称:onprom,代码行数:34,代码来源:UMLDiagramPanel.java

示例13: main

import java.awt.print.PrinterJob; //导入方法依赖的package包/类
public static final void main( String[] parameters ) {
    PrinterJob printjob = PrinterJob.getPrinterJob();
    printjob.setJobName( "Test Print Job" );

    PrintRequestAttributeSet attributes = new HashPrintRequestAttributeSet();
    attributes.add( OrientationRequested.LANDSCAPE );

    try {
        printjob.setPrintable( new Painter() );
        printjob.print( attributes );
    } catch( PrinterException exception ) {
        exception.printStackTrace();
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:15,代码来源:LandscapeStackOverflow.java

示例14: actionPerformed

import java.awt.print.PrinterJob; //导入方法依赖的package包/类
public void actionPerformed(ActionEvent e) {
    PrinterJob job = PrinterJob.getPrinterJob();
    job.setPrintable(this);
    if (job.printDialog()) {
        try {
            job.print();
        } catch (PrinterException ex) {
            ex.printStackTrace();
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:12,代码来源:bug8023392.java

示例15: onOk

import java.awt.print.PrinterJob; //导入方法依赖的package包/类
@Override
protected void onOk() {
    super.onOk();
    final PrinterJob job = framework.getPrinterJob("idef0");
    try {
        printable.setPrintFunctions(panel.getSelectedFunctions());
        job.setPrintable(printable.createPrintable(), printable
                .getPageFormat());
        job.setJobName(printable.getJobName());
        if (job.printDialog()) {

            job.print();
        }
    } catch (final Exception e) {
        e.printStackTrace();
    }
}
 
开发者ID:Vitaliy-Yakovchuk,项目名称:ramus,代码行数:18,代码来源:PrintDialog.java


注:本文中的java.awt.print.PrinterJob.setPrintable方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。