本文整理汇总了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;
}
}
}
示例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);
}
}
}
}
示例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);
}
}
}
示例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: 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);
}
}
}
示例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);
}
}
}
示例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);
}
}
}
示例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);
}
}
}
}
示例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);
}
}
}
示例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);
}
}
}
示例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);
}
示例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());
}
}
}
示例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();
}
}
示例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();
}
}
}
示例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();
}
}