List of usage examples for javax.swing JScrollPane paint
public void paint(Graphics g)
From source file:velocitekProStartAnalyzer.MainWindow.java
private void saveTableAsPng(JScrollPane panel) { btnSaveTableAsPng.addActionListener(new ActionListener() { @Override//from w ww .j av a 2 s . c o m public void actionPerformed(ActionEvent e) { fileChooser.setDialogTitle("Specify a file to save"); int userSelection = fileChooser.showSaveDialog(frame); BufferedImage bufImage = new BufferedImage(panel.getSize().width, panel.getSize().height, BufferedImage.TYPE_INT_RGB); panel.paint(bufImage.createGraphics()); if (userSelection == JFileChooser.APPROVE_OPTION) { File fileToSave = new File(fileChooser.getSelectedFile() + ".png"); System.out.println("Save as file: " + fileToSave.getAbsolutePath()); try { fileToSave.createNewFile(); ImageIO.write(bufImage, "png", fileToSave); statusLabel.setText("Table Screenshot Saved as: " + fileToSave.getName()); } catch (Exception ex) { statusLabel.setText("There was an error during saving"); } } } }); btnSaveTableAsPngForChart.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { fileChooser.setDialogTitle("Specify a file to save"); int userSelection = fileChooser.showSaveDialog(frame); BufferedImage bufImage = new BufferedImage(panel.getSize().width, panel.getSize().height, BufferedImage.TYPE_INT_RGB); panel.paint(bufImage.createGraphics()); if (userSelection == JFileChooser.APPROVE_OPTION) { File fileToSave = new File(fileChooser.getSelectedFile() + ".png"); System.out.println("Save as file: " + fileToSave.getAbsolutePath()); try { fileToSave.createNewFile(); ImageIO.write(bufImage, "png", fileToSave); statusLabel.setText("Table Screenshot Saved as: " + fileToSave.getName()); } catch (Exception ex) { statusLabel.setText("There was an error during saving"); } } } }); }