javax.swing.JPanel.print()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(3.4k)|赞(0)|评价(0)|浏览(137)

本文整理了Java中javax.swing.JPanel.print()方法的一些代码示例,展示了JPanel.print()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JPanel.print()方法的具体详情如下:
包路径:javax.swing.JPanel
类名称:JPanel
方法名:print

JPanel.print介绍

暂无

代码示例

代码示例来源:origin: stackoverflow.com

private void saveView(File saveTo, JPanel view) {

  BufferedImage image = new BufferedImage(view.getPreferredSize().width,
    view.getPreferredSize().height,
    BufferedImage.TYPE_4BYTE_ABGR);

  view.print(image.getGraphics());

  try {
    ImageIO.write(image, "png", saveTo);
  } catch (IOException e) {
    //Handle exception
  }
}

代码示例来源:origin: stackoverflow.com

JPanel panel = new JPanel ();
panel.setLayout(new FlowLayout());
panel.setBackground(Color.WHITE);
panel.add(vv);

Properties p = new Properties(); 
p.setProperty("PageSize","A4"); 

// vv is the VirtualizationViewer

VectorGraphics g = new PDFGraphics2D(new File("Network.pdf"), vv);                  

g.setProperties(p); 
g.startExport(); 
panel.print(g); 
g.endExport();

代码示例来源:origin: freeplane/freeplane

@Override
public void print(final Graphics g) {
  try {
    preparePrinting();
    super.print(g);
  }
  finally {
    isPrinting = false;
  }
}

代码示例来源:origin: SciGraph/SciGraph

private static BufferedImage renderImage(JPanel panel) {
 JFrame frame = new JFrame();
 frame.setUndecorated(true);
 frame.getContentPane().add(panel);
 frame.pack();
 BufferedImage bi = new BufferedImage(panel.getWidth(), panel.getHeight(), BufferedImage.TYPE_INT_ARGB);
 Graphics2D graphics = bi.createGraphics();
 panel.print(graphics);
 graphics.dispose();
 frame.dispose();
 return bi;
}

代码示例来源:origin: stackoverflow.com

void takePicture(JPanel panel) {
  BufferedImage img = new BufferedImage(panel.getWidth(), panel.getHeight(), BufferedImage.TYPE_INT_RGB);
  panel.print(img.getGraphics()); // or: panel.printAll(...);
  try {
    ImageIO.write(img, "jpg", new File("panel.jpg"));
  }
  catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
  }
}

代码示例来源:origin: stackoverflow.com

public BufferedImage createImage(JPanel panel) {

int w = panel.getWidth();
int h = panel.getHeight();
BufferedImage bi = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
Graphics2D g = bi.createGraphics();
panel.print(g);
return bi;
}

代码示例来源:origin: stackoverflow.com

public BufferedImage createImage(JPanel panel) {

int w = panel.getWidth();
int h = panel.getHeight();
BufferedImage bi = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
Graphics2D g = bi.createGraphics();
panel.print(g);
return bi;
}

代码示例来源:origin: org.tentackle/tentackle-swing-print

/**
 * Prints the panel with all its components.
 * <p>
 * {@inheritDoc}
 */
@Override
public void print (Graphics g)  {
 super.print(g);     // prints the container only (i.e. the background)
 // print components
 Component[] comps = getComponents();
 for (int i=0; i < comps.length; i++)  {
  Component c = comps[i];
  Point loc = c.getLocation();
  g.translate(loc.x, loc.y);
  if (c.isVisible())  {
   c.print(g);       // if this a PrintPanel, go recursively down
  }
  g.translate(-loc.x, -loc.y);
 }
}

代码示例来源:origin: stackoverflow.com

PdfTemplate template = contentByte.createTemplate(500, 500);
Graphics2D g2 = template.createGraphics(500, 500);
panel.print(g2);
g2.dispose();
contentByte.addTemplate(template, 30, 300);

代码示例来源:origin: freehep/freehep-vectorgraphics

public static void main(String[] args) throws Exception {
  JPanel yourPanel = new YourPanel();
  
  // run with -Djava.awt.headless=true
  Headless headless = new Headless(yourPanel);
  headless.pack();
  headless.setVisible(true);
  File out = new File("YourPanel.pdf");
  VectorGraphics graphics = new PDFGraphics2D(out, yourPanel);
  graphics.startExport();
  yourPanel.print(graphics);
  graphics.endExport();
}

相关文章

微信公众号

最新文章

更多

JPanel类方法