List of usage examples for javax.swing JPanel print
public void print(Graphics g)
Graphics
. From source file:edu.sdsc.scigraph.services.jersey.writers.ImageWriter.java
private static BufferedImage renderImage(JPanel panel) { JFrame frame = new JFrame(); frame.setUndecorated(true);//from w w w . ja v a 2s .c om 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; }
From source file:gui.images.CodebookVectorProfilePanel.java
/** * Sets the data to be shown.//from w ww . j av a2 s .c om * * @param occurrenceProfile Double array that is the neighbor occurrence * profile of this visual word. * @param codebookIndex Integer that is the index of this visual word. * @param classColors Color[] of class colors. * @param classNames String[] of class names. */ public void setResults(double[] occurrenceProfile, int codebookIndex, Color[] classColors, String[] classNames) { int numClasses = Math.min(classNames.length, occurrenceProfile.length); this.codebookIndex = codebookIndex; this.occurrenceProfile = occurrenceProfile; DefaultPieDataset pieData = new DefaultPieDataset(); for (int cIndex = 0; cIndex < numClasses; cIndex++) { pieData.setValue(classNames[cIndex], occurrenceProfile[cIndex]); } JFreeChart chart = ChartFactory.createPieChart3D("codebook vect " + codebookIndex, pieData, true, true, false); PiePlot plot = (PiePlot) chart.getPlot(); plot.setDirection(Rotation.CLOCKWISE); plot.setForegroundAlpha(0.5f); PieRenderer prend = new PieRenderer(classColors); prend.setColor(plot, pieData); ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new Dimension(140, 140)); chartPanel.setVisible(true); chartPanel.revalidate(); chartPanel.repaint(); JPanel jp = new JPanel(); jp.setPreferredSize(new Dimension(140, 140)); jp.setMinimumSize(new Dimension(140, 140)); jp.setMaximumSize(new Dimension(140, 140)); jp.setSize(new Dimension(140, 140)); jp.setLayout(new FlowLayout()); jp.add(chartPanel); jp.setVisible(true); jp.validate(); jp.repaint(); JFrame frame = new JFrame(); frame.setBackground(Color.WHITE); frame.setUndecorated(true); frame.getContentPane().add(jp); frame.pack(); BufferedImage bi = new BufferedImage(jp.getWidth(), jp.getHeight(), BufferedImage.TYPE_INT_ARGB); Graphics2D graphics = bi.createGraphics(); jp.print(graphics); graphics.dispose(); frame.dispose(); imPanel.removeAll(); imPanel.setImage(bi); imPanel.setVisible(true); imPanel.revalidate(); imPanel.repaint(); }