save.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Rectangle rec = label.getBounds(); BufferedImage img = new BufferedImage(rec.width,rec.height,BufferedImage.TYPE_INT_ARGB); paint(img.getGraphics()); JFileChooser chooser = new JFileChooser(); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); int result = chooser.showDialog(Form.this,"Save"); if (result == JFileChooser.APPROVE_OPTION) { File file = chooser.getSelectedFile(); try { ImageIO.write(img,"*.jpg", file); JOptionPane.showMessageDialog(Form.this,"The image was saved!", "",JOptionPane.INFORMATION_MESSAGE); } catch (IOException ex) { JOptionPane.showMessageDialog(Form.this,"Error!", "",JOptionPane.ERROR_MESSAGE); } } else { JOptionPane.showMessageDialog(Form.this,"Canceled by user"); } } }); 

Does not save, although it seems to work correctly. Help me figure out where I made a mistake.

  • one
    Oh man, it's russian StackOverflow) you must go to the original stackoverflow) - E1mir
  • Or you can translate the question into Russian. - pavel
  • @KryTer_NexT translated) - striker92
  • Listen, I had a similar situation, only with a text file, I could not save files on C:/ disk, changed it to D:/ everything worked) - E1mir
  • the second parameter ImageIO.write (formatName) should be just "jpg" - zRrr

0