Results 1 to 2 of 2
  1. #1
    zerocool1822 is offline Member
    Join Date
    Nov 2012
    Rep Power

    Default java gui menu , saveing

    hello , im trying to get my save function on my menu bar to work right. when i hit save on the menu bar , it creates the file and everything. but the picture is blank. i cant seem to find what i did wrong.

    heres my save method, it supposed to save an image of my GUI canvas , but like i said i comes up blank.
    Java Code:
    public void SaveToDisk(String file) {
    		file = "save.png";
    		// need a buffered image to save the image
    		BufferedImage bufferedImage = 
    			new BufferedImage(150, 
    		Graphics g = bufferedImage.createGraphics();
    		System.out.println("Saving file to disk:" + file); 
    		try {
    			ImageIO.write(bufferedImage, "png", new File(file));
    		} catch (Exception e) {
    			System.out.println("[e] cannot save");
    	public void loadImage() {
    	      try {                
    	    	  image = File("save.png"));
    	       } catch (IOException ex) {
    	    	   System.out.println("[e] cannot load");
    just incase here the action listener for my save button , which im pretty sure is right

    Java Code:
    save.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent e) {

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Blog Entries
    Rep Power

    Default Re: java gui menu , saveing

    What do you mean by "but the picture is blank"? Please provide any details that can help us help you.

    Also this looks quite suspicious:

    Java Code:
    It appears as if you're trying to call paint(...) directly on a Swing component, something that you'll almost never want to do.

Similar Threads

  1. Java Script context menu into JAVA Context Menu...
    By in forum AWT / Swing
    Replies: 1
    Last Post: 08-22-2012, 09:14 AM
  2. Java Menu Help
    By 73challenger in forum New To Java
    Replies: 2
    Last Post: 12-10-2009, 06:19 AM
  3. Fill a menu dynamically when menu is shown
    By Java Tip in forum SWT Tips
    Replies: 0
    Last Post: 07-07-2008, 04:47 PM
  4. React to menu action and checkbox menu
    By Java Tip in forum javax.swing
    Replies: 0
    Last Post: 06-27-2008, 07:50 PM
  5. Replies: 7
    Last Post: 05-09-2008, 07:54 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts