Results 1 to 8 of 8
Thread: Saving JFrame
- 12-03-2008, 08:06 AM #1
Member
- Join Date
- Nov 2008
- Posts
- 11
- Rep Power
- 0
- 12-03-2008, 01:17 PM #2
Yes,you can do a screenshot ,try to find on google how to make a screenshot in java in special area on desktop
- 12-03-2008, 03:58 PM #3
Member
- Join Date
- Nov 2008
- Posts
- 11
- Rep Power
- 0
I've looked on google on how to do this with no luck if you have a link to a guide or something i would greatly appreciatte it if you could post it. THnkas
-
I haven't done this but you can draw the JFrame I believe using a BufferedImage's Graphics object and the JFrame's paint command and then save this as a JPG. Again, I've not done this but I think I've seen it somewhere.
-
This program will capture a JFrame except not the title bar, and I haven't yet figured out how to do that:
Java Code:import java.awt.Dimension; import java.awt.Graphics; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import javax.imageio.ImageIO; import javax.swing.JButton; import javax.swing.JComponent; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.SwingUtilities; public class PaintJFrame { private static final Dimension MAIN_SIZE = new Dimension(400, 300); private JPanel mainPanel = new JPanel(); public PaintJFrame() { JButton makeImageBtn = new JButton("Make Image"); makeImageBtn.addActionListener(new BtnListener()); mainPanel.add(makeImageBtn); mainPanel.setPreferredSize(MAIN_SIZE); } public JComponent getPanel() { return mainPanel; } private class BtnListener implements ActionListener { public void actionPerformed(ActionEvent arg0) { JFrame win = (JFrame)SwingUtilities.getWindowAncestor(mainPanel); Dimension size = win.getSize(); //BufferedImage image = new BufferedImage(size.width, size.height, BufferedImage.TYPE_INT_RGB); BufferedImage image = (BufferedImage)win.createImage(size.width, size.height); Graphics g = image.getGraphics(); win.paint(g); g.dispose(); try { ImageIO.write(image, "jpg", new File("MyFrame2.jpg")); } catch (IOException e) { e.printStackTrace(); } } } private static void createAndShowGUI() { JFrame frame = new JFrame("PaintJFrame Application"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().add(new PaintJFrame().getPanel()); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); } public static void main(String[] args) { javax.swing.SwingUtilities.invokeLater(new Runnable() { public void run() { createAndShowGUI(); } }); } }
- 12-03-2008, 07:41 PM #6
Member
- Join Date
- Nov 2008
- Posts
- 11
- Rep Power
- 0
I'll try the code you posted I am making a program that allows the user to create a family tree and I just need to save the picture of the tree so this should work I'll try it out and post the results.
- 12-03-2008, 08:50 PM #7
Member
- Join Date
- Dec 2008
- Posts
- 41
- Rep Power
- 0
in the top right corner of ur keyboard(PC) theres a button that says
Prt Sc
Sys Rq
when u have the JFrame up hit that button open up paint hit the edit button and then copy. then u can save it as .jpg or .gif or wutever else u like.
- 12-03-2008, 09:19 PM #8
Similar Threads
-
Saving changes done through a program
By xcallmejudasx in forum New To JavaReplies: 0Last Post: 12-02-2008, 04:53 PM -
Saving data...?
By easyRyder in forum New To JavaReplies: 8Last Post: 07-15-2008, 03:14 AM -
Saving Values
By Sysem in forum New To JavaReplies: 10Last Post: 06-02-2008, 06:29 PM -
Saving application settings
By mwildam in forum New To JavaReplies: 0Last Post: 11-16-2007, 02:30 PM -
Saving Variables
By Fish in forum New To JavaReplies: 6Last Post: 06-25-2007, 08:20 PM
Bookmarks