Example usage for javax.swing JScrollPane paint

List of usage examples for javax.swing JScrollPane paint

Introduction

In this page you can find the example usage for javax.swing JScrollPane paint.

Prototype

public void paint(Graphics g) 

Source Link

Document

Invoked by Swing to draw components.

Usage

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");
                }

            }
        }
    });

}