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


Java PrinterJob类代码示例

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


PrinterJob类属于java.awt.print包,在下文中一共展示了PrinterJob类的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: getPageFormat

import java.awt.print.PrinterJob; //导入依赖的package包/类
/**
 * Get an instance of {@link java.awt.print.PageFormat}.
 * @param pj {@link java.awt.print.PrinterJob} which is 
 * associated with the default printer.
 * @return an instance of <code>PageFormat</code> that describes the size and
 * orientation of a page to be printed.
 */
public static PageFormat getPageFormat(PrinterJob pj) {
    PageFormat pageFormat = null;
    pageFormat = pj.defaultPage();
    Paper p = pageFormat.getPaper();
    int pageOrientation = getPreferences().getInt(PROP_PAGE_ORIENTATION, pageFormat.getOrientation());
    double paperWidth = getPreferences().getDouble(PROP_PAGE_WIDTH, p.getWidth());
    double paperHeight = getPreferences().getDouble(PROP_PAGE_HEIGHT, p.getHeight());
    
    double iaWidth = getPreferences().getDouble(PROP_PAGE_IMAGEABLEAREA_WIDTH, p.getImageableWidth());
    double iaHeight = getPreferences().getDouble(PROP_PAGE_IMAGEABLEAREA_HEIGHT, p.getImageableHeight());
    double iaX = getPreferences().getDouble(PROP_PAGE_IMAGEABLEAREA_X, p.getImageableX());
    double iaY = getPreferences().getDouble(PROP_PAGE_IMAGEABLEAREA_Y, p.getImageableY());
    
    pageFormat.setOrientation(pageOrientation);
    p.setSize(paperWidth, paperHeight);
    p.setImageableArea(iaX, iaY, iaWidth, iaHeight);
    pageFormat.setPaper(p);
    return pageFormat;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:27,代码来源:PrintPreferences.java

示例3: main

import java.awt.print.PrinterJob; //导入依赖的package包/类
public static void main(String[] args)  throws Exception {
    job = PrinterJob.getPrinterJob();
    PrintService prtSrv = job.getPrintService();
    if (job.getPrintService() == null) {
        System.out.println("No printers. Test cannot continue");
        return;
    }
    if (!prtSrv.isAttributeCategorySupported(JobSheets.class)) {
        return;
    }
    SwingUtilities.invokeAndWait(() -> {
        doTest(BannerTest::printTest);
    });
    mainThread = Thread.currentThread();
    try {
        Thread.sleep(180000);
    } catch (InterruptedException e) {
        if (!testPassed && testGeneratedInterrupt) {
            throw new RuntimeException("Banner page did not print");
        }
    }
    if (!testGeneratedInterrupt) {
        throw new RuntimeException("user has not executed the test");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:26,代码来源:BannerTest.java

示例4: getPageFormat

import java.awt.print.PrinterJob; //导入依赖的package包/类
public PageFormat getPageFormat() {
    PrinterJob job = PrinterJob.getPrinterJob();

    if (myPageFormat == null) {
        myPageFormat = job.defaultPage();

        // restore
        myPageFormat.setOrientation(round(get(PAGE_ORIENTATION, PageFormat.PORTRAIT)));
        Paper paper = myPageFormat.getPaper();

        if (get(PAPER_WIDTH, null) != null && get(PAPER_HEIGHT, null) != null) {
            paper.setSize(get(PAPER_WIDTH, INCH), get(PAPER_HEIGHT, INCH));
        }
        if (get(AREA_X, null) != null && get(AREA_Y, null) != null && get(AREA_WIDTH, null) != null && get(AREA_HEIGHT, null) != null) {
            paper.setImageableArea(get(AREA_X, INCH), get(AREA_Y, INCH), get(AREA_WIDTH, INCH), get(AREA_HEIGHT, INCH));
        }
        myPageFormat.setPaper(paper);
    }
    return myPageFormat;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:Config.java

示例5: 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();
		PageFormat format = pj.pageDialog(graphComponent
				.getPageFormat());

		if (format != null)
		{
			graphComponent.setPageFormat(format);
			graphComponent.zoomAndCenter();
		}
	}
}
 
开发者ID:ModelWriter,项目名称:Tarski,代码行数:21,代码来源:EditorActions.java

示例6: 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;
    }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:Printer.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: getCustomEditor

import java.awt.print.PrinterJob; //导入依赖的package包/类
/**
* @return <tt>null</tt> Shows pageDialog, however.
*/
public java.awt.Component getCustomEditor() {
    PageFormat pf = (PageFormat) getValue();
    PrinterJob pj = PrinterJob.getPrinterJob();
    PageFormat npf = pj.pageDialog(pf);

    //setValue(npf);
    ((PrintSettings)PrintSettings.findObject(PrintSettings.class)).setPageFormat((PageFormat) npf.clone());
    pj.cancel();

    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:15,代码来源:PrintSettings.java

示例9: 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

示例10: 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) {}
}
 
开发者ID:kristian,项目名称:JDigitalSimulator,代码行数:10,代码来源:Application.java

示例11: main

import java.awt.print.PrinterJob; //导入依赖的package包/类
public static void main(String args[]) throws Exception {
    String[] instructions
            = {
                "Select Pages Range From instead of All in print dialog. ",
                "Then select Print"
            };
    SwingUtilities.invokeAndWait(() -> {
        JOptionPane.showMessageDialog((Component) null,
                instructions, "Instructions",
                JOptionPane.INFORMATION_MESSAGE);
    });
    HashPrintRequestAttributeSet as = new HashPrintRequestAttributeSet();
    PrinterJob j = PrinterJob.getPrinterJob();
    j.setPageable(new PrintAttributeUpdateTest());
    as.add(DialogTypeSelection.NATIVE);
    j.printDialog(as);
    if (as.containsKey(PageRanges.class) == false) {
        throw new RuntimeException("Print Dialog did not update "
                + " attribute set with page range");
    }
    Attribute attrs[] = as.toArray();
    for (int i = 0; i < attrs.length; i++) {
        System.out.println("attr " + attrs[i]);
    }
    j.print(as);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:27,代码来源:PrintAttributeUpdateTest.java

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

示例13: doPrint

import java.awt.print.PrinterJob; //导入依赖的package包/类
public void doPrint( int i ) {
    if ( printer == null ) {
        printer = PrinterJob.getPrinterJob();
        page = printer.defaultPage();
    }
    printMode = i;
    printer.setPrintable( fc, page );

    if ( printer.printDialog() ) {
        try {
            printer.print();
        }
        catch ( Exception e ) {
            f2dt.fireChangeStatus( "ERROR: Printing Failed; See Stack Trace", true );
        }
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:18,代码来源:FontPanel.java

示例14: 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

示例15: main

import java.awt.print.PrinterJob; //导入依赖的package包/类
public static void main(String[] args) throws Exception {

        String[] instructions =
         {
             "Visual inspection of the dialog is needed. ",
             "It should be a Printer Job Setup Dialog",
             "Do nothing except Cancel",
             "You must NOT press OK",
         };
        SwingUtilities.invokeAndWait(() -> {
            JOptionPane.showMessageDialog(
                    (Component) null,
                    instructions,
                    "information", JOptionPane.INFORMATION_MESSAGE);
        });
        PrinterJob pj = PrinterJob.getPrinterJob();
        PrintRequestAttributeSet pSet = new HashPrintRequestAttributeSet();
        pSet.add(DialogTypeSelection.NATIVE);
        if ((pj.pageDialog(pSet)) != null) {
            throw
            new RuntimeException("PrinterJob.pageDialog(PrintRequestAttributeSet)"
                        + " does not return null when dialog is cancelled");
        }
    }
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:25,代码来源:PageDlgApp.java


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