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());
}
}
}
UMLDiagramPanel.java 文件源码
java
阅读 28
收藏 0
点赞 0
评论 0
项目:onprom
作者:
评论列表
文章目录