Save as

Posted on 2006-05-26
Last Modified: 2010-08-05

I have an option caled save as..

Wht i am looking for is that when user click save as , a dialog box should appear save the format as .cdf and the filename and path is saved .

Pls help

[filename,pathname] = uiputfile('*.cdf','Save file name');
Question by:Jasbir21
    1 Comment
    LVL 14

    Accepted Solution

    With some modifications, this should do the trick:

    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import java.text.*;
    import javax.accessibility.*;

    public class Z extends JFrame implements Runnable, ActionListener {
      JButton jb = new JButton("Save as...");
      public void init() {
      public void actionPerformed(ActionEvent ae) {
        JFileChooser jfc = new JFileChooser(".");
        jfc.setFileFilter(new javax.swing.filechooser.FileFilter() {
          public boolean accept(File f) {
              return true;
            return false;
          public String getDescription() {
            return "cdf file format. (*.CDF)";
        int ret = jfc.showSaveDialog(this);
        if(ret == jfc.APPROVE_OPTION) {
          File f = jfc.getSelectedFile();
          // do whatever You need here
      public void run() {
      public void center(Component c) {
        Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
        setLocation((dim.width - c.getWidth()) / 2, (dim.height - c.getHeight()) / 2);
      public static void main(String[] args) {
        SwingUtilities.invokeLater(new Z());

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    fix34  challenge 9 70
    countHi challenge 25 61
    groovy example issue 10 33
    What is the latest versions eclipse neon 2 57
    If you have upgraded to Java2 update 10 on a Microsoft Windows client, you may have discovered that your Java application does not work as it did before.  For example, the colors of your Java2D graphic may be all wrong for no apparent reason. Aft…
    By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
    This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
    Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now