Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6042437
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:47:25+00:00 2026-05-23T06:47:25+00:00

I have successfully done this before but now after running the program numerous times

  • 0

I have successfully done this before but now after running the program numerous times the failure comes at the screenshot is too fast. And it won’t take the correct image it takes it as the jframe is fading in. How do I fix this?Error

Edit : So basically I’m trying to capture the image of the Jpanels inside the JFrame but in the process of doing this by calling it out of an excel macro the image captured turns out to be the one above instead of the image I need.

import java.io.*;
import javax.swing.*;
import java.awt.event.*;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
public class TimeTableGraphicsRunner extends JFrame
{
    public TimeTableGraphicsRunner()
    {
        getContentPane().setLayout(new BoxLayout(getContentPane(),BoxLayout.Y_AXIS));
    }
    public void load(TimeTablePanel pan)
    {
        pan.setTitle(x.getTitle(TimeTable.titleCount));
        getContentPane().add(pan);
    }
    public void run()throws Exception
    {
        System.out.println("Creating image in panel");
        //setSize(TimeTable.width,TimeTable.height);
        getContentPane().setPreferredSize(new java.awt.Dimension(TimeTable.width,TimeTable.height));
        pack();
        setVisible(true);
        System.out.println("Image is in panel");
        grabScreenShot();
        System.out.println("Cleaning up");
        setVisible(false);
        System.out.println("Finished");
        System.exit(0);
    }
    private void grabScreenShot() throws Exception
    {
        BufferedImage image = (BufferedImage)createImage(getContentPane().getSize().width,getContentPane().getSize().height);
        getContentPane().paint(image.getGraphics());
        try{
            ImageIO.write(image, "png", new File("C:\\Users\\"+TimeTable.user+"\\AppData\\TimeLineMacroProgram\\TimeLine.png"));
            System.out.println("Image was created");
        }
        catch (IOException e){
            System.out.println("Had trouble writing the image.");
            throw e;
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T06:47:26+00:00Added an answer on May 23, 2026 at 6:47 am

    It takes time for the operating system to construct and display the frame. Thus the screenshot action is being executed before the frame can be fully displayed.

    You can get around it in a couple of ways. The best is probably to use a ComponentListener.

    public class TimeTableGraphicsRunner extends JFrame implements ComponentListener
    {
        public TimeTableGraphicsRunner()
        {
            addComponentListener(this);
            ... snip
        }
    
        ... snip
    
        public void componentShown(ComponentEvent e) {
            grabScreenShot();
            System.out.println("Cleaning up");
            setVisible(false);
            System.out.println("Finished");
            System.exit(0);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What I have now (which successfully loads the plug-in) is this: Assembly myDLL =
I believe that I have successfully impersonated my own user account while running an
I have been using Hibernate very successfully, but today I noticed a bizarre phenomenon
I have successfully connected to an Oracle database (10g) from C# (Visual Studio 2008)
I have a Rails app that I have successfully tested with Mongrel and Webkit.
I'm familiar with the LAMP stack and over the years have successfully deployed a
using the Code Snippet for sending email in VB.Net I have successfully sent an
I'm just learning Qt with C++. I have successfully implemented signals and slots to
How can I set a parameter of a sub-report? I have successfully hooked myself
I have a script that successfully encrypts a credit card. I need it to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.