output a jFrame to jpeg or bitmap
graphics, java
Solution
Another approach is to tell your `Component` to `paint()` itself into a `BufferedImage`, as seen in this complete example. The `Container` returned by a `JFrame`'s `getContentPane()` method is suitable. In summary:
Component component = f.getContentPane();
BufferedImage image = new BufferedImage(…);
component.paint(image.getGraphics());
ImageIO.write(image,…);
Problem
I've been working on an assignment, and have all the requirements completed. The project is to compare the differences in runtime between a linear search algorithm and a binary search. I have a graph class that puts out the results of those searches in a xy graph. The graph object is a Turtle class that extends JFrame. Is there any way I can convert that graph object to a bitmap and save it for future printing? The professor requires printouts of the results. Since I don't want a printout of every time the program is run, I would prefer to save the graphics results in a designated folder, rather than using screen-grab. Unfortunately, I haven't come up with any answers on Google or here. Is something like this even possible?