Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: How to save Image into a package by JButton save?

  1. #1
    Member
    Join Date
    Apr 2012
    Posts
    57
    My Mood
    Angelic
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default How to save Image into a package by JButton save?

    Good Evening/Morning/ or just Late Night

    I have a question I'm trying to load an image into my JLabel and when it's loaded I want to save it. Can you please help me or give me some advices how to do it?

    So far I have this:
    JButton OpenIcon = new JButton("Open New map");
    		OpenIcon.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent arg0) {
    				JFileChooser chooser = new JFileChooser();
    				chooser.addChoosableFileFilter(new ImageFileFilter());
    				int returnVal = chooser.showOpenDialog(null);
     
    				if(returnVal ==JFileChooser.APPROVE_OPTION){
    					File file =chooser.getSelectedFile();
    					Fpath = file.getPath();
    					ImageIcon Sicon = new ImageIcon(Fpath);
    					pic.setIcon(Sicon);
    					pic.repaint();
     
    				}
     
    			}
    		});

    For browsing the Ion into my Jlabel, now I want to save it can somebody pls help me?


  2. #2
    Member
    Join Date
    Apr 2012
    Posts
    57
    My Mood
    Angelic
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: How to save Image into a package by JButton save?

    Back with more code and more questions:


    JButton Save = new JButton("Save New Map");
    		Save.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent e) {
    				JFileChooser chooserS = new JFileChooser();
    				int returnVal = chooserS.showSaveDialog(null);
    				if(returnVal == JFileChooser.APPROVE_OPTION){
    					File filr =chooserS.getSelectedFile();
    					log.append("Saving:" + filr.getName() + "." + "\n");
     
    				}else{
    					log.append("Save command cancelled by user");
    				}
    				log.setCaretPosition(log.getDocument().getLength());
    			}
    		});


    1st question --- Why does sun use JTextArea for log? I dont get it.
    2nd question --- log.append("Saving:" + filr.getName() + "." + "\n"); why is here the \n ?? I can't select the extension like this.
    So how can I select the extension????

Similar Threads

  1. Save JSON obj via Jfilechooser
    By nautilusz in forum File I/O & Other I/O Streams
    Replies: 0
    Last Post: March 24th, 2012, 06:15 AM
  2. Save JPanel as image
    By fahien in forum AWT / Java Swing
    Replies: 1
    Last Post: March 4th, 2011, 08:20 AM
  3. How and where do you save user settings?
    By snytkine in forum AWT / Java Swing
    Replies: 3
    Last Post: October 12th, 2010, 05:46 AM
  4. Can't get it to save stuff with JFileChooser
    By javapenguin in forum What's Wrong With My Code?
    Replies: 35
    Last Post: August 11th, 2010, 04:13 AM
  5. Arraylist Save and Load
    By frankycool in forum Collections and Generics
    Replies: 1
    Last Post: November 14th, 2009, 06:48 AM