javax.swing.JComponent#print ( )源码实例Demo

下面列出了javax.swing.JComponent#print ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: mzmine3   文件: SwingExportUtil.java
public static void writeToSVG(JComponent panel, File fileName) throws IOException {
  // print the panel to pdf
  int width = panel.getWidth();
  int height = panel.getWidth();
  logger.info(
      () -> MessageFormat.format("Exporting panel to SVG file (width x height; {0} x {1}): {2}",
          width, height, fileName.getAbsolutePath()));

  // Get a DOMImplementation
  DOMImplementation domImpl = SVGDOMImplementation.getDOMImplementation();
  org.w3c.dom.Document document = domImpl.createDocument(null, "svg", null);
  SVGGraphics2D svgGenerator = new SVGGraphics2D(document);
  svgGenerator.setSVGCanvasSize(new Dimension(width, height));
  panel.print(svgGenerator);

  boolean useCSS = true; // we want to use CSS style attribute

  try (Writer out = new OutputStreamWriter(new FileOutputStream(fileName), "UTF-8")) {
    svgGenerator.stream(out, useCSS);
  }
}
 
源代码2 项目: mzmine2   文件: SwingExportUtil.java
public static void writeToSVG(JComponent panel, File fileName) throws IOException {
  // print the panel to pdf
  int width = panel.getWidth();
  int height = panel.getWidth();
  logger.info(
      () -> MessageFormat.format("Exporting panel to SVG file (width x height; {0} x {1}): {2}",
          width, height, fileName.getAbsolutePath()));

  // Get a DOMImplementation
  DOMImplementation domImpl = SVGDOMImplementation.getDOMImplementation();
  org.w3c.dom.Document document = domImpl.createDocument(null, "svg", null);
  SVGGraphics2D svgGenerator = new SVGGraphics2D(document);
  svgGenerator.setSVGCanvasSize(new Dimension(width, height));
  panel.print(svgGenerator);

  boolean useCSS = true; // we want to use CSS style attribute

  try (Writer out = new OutputStreamWriter(new FileOutputStream(fileName), "UTF-8")) {
    svgGenerator.stream(out, useCSS);
  }
}
 
源代码3 项目: mzmine3   文件: SwingExportUtil.java
/**
 * Writes swing to pdf
 * 
 * @param panel
 * @param fileName
 * @throws DocumentException
 * @throws Exception
 */
public static void writeToPDF(JComponent panel, File fileName)
    throws IOException, DocumentException {
  // print the panel to pdf
  int width = panel.getWidth();
  int height = panel.getHeight();
  logger.info(
      () -> MessageFormat.format("Exporting panel to PDF file (width x height; {0} x {1}): {2}",
          width, height, fileName.getAbsolutePath()));
  Document document = new Document(new Rectangle(width, height));
  PdfWriter writer = null;
  try {
    writer = PdfWriter.getInstance(document, new FileOutputStream(fileName));
    document.open();
    PdfContentByte contentByte = writer.getDirectContent();
    PdfTemplate template = contentByte.createTemplate(width, height);
    Graphics2D g2 = new PdfGraphics2D(contentByte, width, height, new DefaultFontMapper());
    panel.print(g2);
    g2.dispose();
    contentByte.addTemplate(template, 0, 0);
    document.close();
    writer.close();
  } finally {
    if (document.isOpen()) {
      document.close();
    }
  }
}
 
源代码4 项目: mzmine3   文件: SwingExportUtil.java
/**
 * Writes swing to EMF
 * 
 * @param panel
 * @param fileName
 * @throws Exception
 */
public static void writeToEMF(JComponent panel, File fileName) throws IOException {
  // print the panel to pdf
  int width = panel.getWidth();
  int height = panel.getWidth();
  logger.info(
      () -> MessageFormat.format("Exporting panel to EMF file (width x height; {0} x {1}): {2}",
          width, height, fileName.getAbsolutePath()));

  VectorGraphics g = new EMFGraphics2D(fileName, new Dimension(width, height));
  g.startExport();
  panel.print(g);
  g.endExport();
}
 
源代码5 项目: netbeans   文件: ComponentPanel.java
@Override
    public void print(Graphics g) {
        for (JComponent component : myComponents) {
            component.print(g);
//          g.setColor(java.awt.Color.green);
//          g.drawRect(0, 0, getWidth(component), getHeight(component));
            g.translate(getWidth(component), 0);
        }
    }
 
源代码6 项目: mzmine2   文件: SwingExportUtil.java
/**
 * Writes swing to pdf
 * 
 * @param panel
 * @param fileName
 * @throws DocumentException
 * @throws Exception
 */
public static void writeToPDF(JComponent panel, File fileName)
    throws IOException, DocumentException {
  // print the panel to pdf
  int width = panel.getWidth();
  int height = panel.getHeight();
  logger.info(
      () -> MessageFormat.format("Exporting panel to PDF file (width x height; {0} x {1}): {2}",
          width, height, fileName.getAbsolutePath()));
  Document document = new Document(new Rectangle(width, height));
  PdfWriter writer = null;
  try {
    writer = PdfWriter.getInstance(document, new FileOutputStream(fileName));
    document.open();
    PdfContentByte contentByte = writer.getDirectContent();
    PdfTemplate template = contentByte.createTemplate(width, height);
    Graphics2D g2 = new PdfGraphics2D(contentByte, width, height, new DefaultFontMapper());
    panel.print(g2);
    g2.dispose();
    contentByte.addTemplate(template, 0, 0);
    document.close();
    writer.close();
  } finally {
    if (document.isOpen()) {
      document.close();
    }
  }
}
 
源代码7 项目: mzmine2   文件: SwingExportUtil.java
/**
 * Writes swing to EMF
 * 
 * @param panel
 * @param fileName
 * @throws Exception
 */
public static void writeToEMF(JComponent panel, File fileName) throws IOException {
  // print the panel to pdf
  int width = panel.getWidth();
  int height = panel.getWidth();
  logger.info(
      () -> MessageFormat.format("Exporting panel to EMF file (width x height; {0} x {1}): {2}",
          width, height, fileName.getAbsolutePath()));

  VectorGraphics g = new EMFGraphics2D(fileName, new Dimension(width, height));
  g.startExport();
  panel.print(g);
  g.endExport();
}
 
源代码8 项目: dragonwell8_jdk   文件: bug4337267.java
void printComponent(JComponent c, TestBufferedImage i) {
    Graphics g = i.getGraphics();
    g.setColor(c.getBackground());
    g.fillRect(0, 0, i.getWidth(), i.getHeight());
    c.print(g);
}
 
源代码9 项目: TencentKona-8   文件: bug4337267.java
void printComponent(JComponent c, TestBufferedImage i) {
    Graphics g = i.getGraphics();
    g.setColor(c.getBackground());
    g.fillRect(0, 0, i.getWidth(), i.getHeight());
    c.print(g);
}
 
源代码10 项目: jdk8u60   文件: bug4337267.java
void printComponent(JComponent c, TestBufferedImage i) {
    Graphics g = i.getGraphics();
    g.setColor(c.getBackground());
    g.fillRect(0, 0, i.getWidth(), i.getHeight());
    c.print(g);
}
 
源代码11 项目: openjdk-jdk8u   文件: bug4337267.java
void printComponent(JComponent c, TestBufferedImage i) {
    Graphics g = i.getGraphics();
    g.setColor(c.getBackground());
    g.fillRect(0, 0, i.getWidth(), i.getHeight());
    c.print(g);
}
 
源代码12 项目: openjdk-jdk8u-backup   文件: bug4337267.java
void printComponent(JComponent c, TestBufferedImage i) {
    Graphics g = i.getGraphics();
    g.setColor(c.getBackground());
    g.fillRect(0, 0, i.getWidth(), i.getHeight());
    c.print(g);
}
 
源代码13 项目: openjdk-jdk9   文件: bug4337267.java
void printComponent(JComponent c, TestBufferedImage i) {
    Graphics g = i.getGraphics();
    g.setColor(c.getBackground());
    g.fillRect(0, 0, i.getWidth(), i.getHeight());
    c.print(g);
}
 
源代码14 项目: jdk8u-jdk   文件: bug4337267.java
void printComponent(JComponent c, TestBufferedImage i) {
    Graphics g = i.getGraphics();
    g.setColor(c.getBackground());
    g.fillRect(0, 0, i.getWidth(), i.getHeight());
    c.print(g);
}
 
源代码15 项目: hottub   文件: bug4337267.java
void printComponent(JComponent c, TestBufferedImage i) {
    Graphics g = i.getGraphics();
    g.setColor(c.getBackground());
    g.fillRect(0, 0, i.getWidth(), i.getHeight());
    c.print(g);
}
 
源代码16 项目: openjdk-8-source   文件: bug4337267.java
void printComponent(JComponent c, TestBufferedImage i) {
    Graphics g = i.getGraphics();
    g.setColor(c.getBackground());
    g.fillRect(0, 0, i.getWidth(), i.getHeight());
    c.print(g);
}
 
源代码17 项目: openjdk-8   文件: bug4337267.java
void printComponent(JComponent c, TestBufferedImage i) {
    Graphics g = i.getGraphics();
    g.setColor(c.getBackground());
    g.fillRect(0, 0, i.getWidth(), i.getHeight());
    c.print(g);
}
 
源代码18 项目: jdk8u_jdk   文件: bug4337267.java
void printComponent(JComponent c, TestBufferedImage i) {
    Graphics g = i.getGraphics();
    g.setColor(c.getBackground());
    g.fillRect(0, 0, i.getWidth(), i.getHeight());
    c.print(g);
}
 
源代码19 项目: jdk8u-jdk   文件: bug4337267.java
void printComponent(JComponent c, TestBufferedImage i) {
    Graphics g = i.getGraphics();
    g.setColor(c.getBackground());
    g.fillRect(0, 0, i.getWidth(), i.getHeight());
    c.print(g);
}
 
源代码20 项目: jdk8u-dev-jdk   文件: bug4337267.java
void printComponent(JComponent c, TestBufferedImage i) {
    Graphics g = i.getGraphics();
    g.setColor(c.getBackground());
    g.fillRect(0, 0, i.getWidth(), i.getHeight());
    c.print(g);
}