How can I set extensions in "File of type" field in JFileChooser

I am using JFileChooser to get the file for opening or saving activities.
I want to restrict the user for file type... during opening or saving a specific file.
Bydefault it is set to "All types *.*". Instead of *.* I want to add options like *.doc, *.txt.
secondly when a user double clicks on a directory, its name appear in the File name text box. I want to disable this. I want to initially set a file name their, which will change only when the user clicks in that text field and type a file name.
Kindly help me regarding this problem.

You can restrict the file types by using the javax.swing.filechooser.FileFilter
Look up the API docs for details.
I'm not sure how you would restrict the user from double-clicking on a directory.

Similar Messages

  • How can I set a default file for JFileChooser

    Hi. I am developing a p2p chat application and I have to unrelated questions.
    1. How can I set a default file name for JFileChooser, to save a completly new file?
    2. I have a JTextArea that I append recieved messages. But when a message is appended, the whole desktop screen refreshes. How can I prevent that?
    Hope I was clear. Thanks in advance.

    Thank you for the first answer, it solved my problem. Here is the code for 2nd question, I've trimmed it a lot, hope I didn't cut off any critical code
    public class ConversationWindow extends JFrame implements KeyListener,MessageArrivedListener,ActionListener,IOnlineUsrComp{
         private TextArea incomingArea;
         private Conversation conversation;
         private JTextField outgoingField;
         private JScrollPane incomingTextScroller;
         private String userName;
         private JButton inviteButton;
         private JButton sendFileButton;
         private JFileChooser fileChooser;
         private FontMetrics fontMetrics;
         private HashMap<String, String> onlineUserMap;
         public void MessageArrived(MessageArrivedEvent e) {
              showMessage(e.getArrivedMessage());
         public ConversationWindow(Conversation conversation)
              this.conversation=conversation;
              userName=User.getInstance().getUserName();
              sendFileButton=new JButton("Dosya G�nder");
              sendFileButton.addActionListener(this);
              inviteButton=new JButton("Davet et");
              inviteButton.addActionListener(this);
              incomingArea=new TextArea();
              incomingArea.setEditable(false);
              incomingArea.setFont(new Font("Verdana",Font.PLAIN,12));
              fontMetrics =incomingArea.getFontMetrics(incomingArea.getFont());
              incomingArea.setPreferredSize(new Dimension(300,300));
              outgoingField=new JTextField();
              outgoingField.addKeyListener(this);
              incomingTextScroller=new JScrollPane(incomingArea);          
              JPanel panel=new JPanel();
              panel.setLayout(new BoxLayout(panel,BoxLayout.PAGE_AXIS));
              panel.add(inviteButton);
              panel.add(sendFileButton);
              panel.add(incomingTextScroller);
              panel.add(outgoingField);
              add(panel);
              pack();
              setTitle("Ki&#351;iler:");
              setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
              setLocationRelativeTo(null);
              addWindowListener(new CloseAdapter());
         //Sends the message to other end
         public void keyPressed(KeyEvent e) {
              if(e.getKeyCode()==KeyEvent.VK_ENTER && e.getSource()==outgoingField)
                   String message=outgoingField.getText();
                   if(message.equals("")) return;
                   showMessage(userName+": "+message);
                   conversation.sendMessages(userName+": "+message);
                   outgoingField.setText("");     
         //Displays the recieved message
         public void showMessage(String message)
              if(fontMetrics.stringWidth(message)>incomingArea.getWidth())
                   int mid=message.length()/2;
                   StringBuilder sbld=new StringBuilder(message);
                   for(;mid<message.length();mid++)
                        if(message.charAt(mid)==' ')
                             sbld.setCharAt(mid, '\n');
                             message=sbld.toString();
                             break;
              incomingArea.append("\n"+message);
    }

  • How can I set my "attach file" system to always show the date and offer to resort?

    When I want to attach a file to an email, or save it for that matter, I have to turn on Details instead of List in the View Menu. How can I set Thunderbird to have Details on as my default.
    Thanks!

    For use in the BB, the on-device format must be used...no PC contains the necessary file structure that the BB needs to find on the card in order to use it correctly. If you can no longer read the card via the BB nor the PC, then it's quite likely that your data is already destroyed. But, there are several PC utilities that claim to be able to recover Flash Memory devices such as SD cards...you should perhaps check those out (Zero Sum something or other? Can't recall specifically, but google will be your best friend in your quest.)
    Good luck!
    Occam's Razor nearly always applies when troubleshooting technology issues!
    If anyone has been helpful to you, please show your appreciation by clicking the button inside of their post. Please click here and read, along with the threads to which it links, for helpful information to guide you as you proceed. I always recommend that you treat your BlackBerry like any other computing device, including using a regular backup schedule...click here for an article with instructions.
    Join our BBM Channels
    BSCF General Channel
    PIN: C0001B7B4   Display/Scan Bar Code
    Knowledge Base Updates
    PIN: C0005A9AA   Display/Scan Bar Code

  • How can I set up SMB file sharing to share my PC external hard drive on my Mac with no password protection?

    I am having the worst trouble with two things. I am very aware how to get the server to show up via SMB, but every time I log off the Macbook, the server's disappear. OK, so I went into "System Preferences" and hit "Users and Accounts" and added the server as a log in item. Worked well, except how do I stop that password prompt from coming up? I am using a Guest account with no password but I continue to get the password prompt. There is nowhere to hit remember password or anything. I have the option to remember the password in the keychain but I have no way of preventing the pop up.
    Another issue I'm having is I have a Canon Pixma MP620 printer connected to my PC through USB. Three other PC's can connect wirelessly to print through the home network. My Mac does not find the printer, and when I manually add it, it recognizes it but WILL NOT print. It comes up with error messages like Authentican Required and connection issues between printers.
    I have no password protection on my PC and have enabled sharing of all devices and folders through the Homegroup on the PC. I just can't figure it out. I am new to Mac and would love to get these two things figured out.
    Thanks in advance for reading!

    Hi Bengt, Thanks for your input, much appreciated.
    I have a WD 1TIG hard drive and are using usb connection, is it possible to use fire wire with these? I have had trouble with a lot of the videos I Imported, once they downloaded the file in the viewer window showed up blank and when I mouse over them it places a picture of another file in the window and wont drag and drop into the movie window, like their corrupted or something? Had to delete just about all of them and start again. Also is it possible to select a bunch of videos in the viewer window as to change the dates to the correct dates? All I have been able to do is "select all" which is no help.

  • Interactive Form Element 7.1:  How can I set the default file name?

    I am using Interactive Form Element with 7.1 to display a pdf.  When one clicks the save button in Adobe's toolbar, the dialog defaults the file name to "F.pdf".  Is there a way to default this to a different value?

    Making customisation from the default profile is generally considered poor practice and quite often doesn't work out as planned. (If you're interested in some more information on this, [http://mockbox.net/windows-7/227-customise-windows-7-default-profile.html see here] see here)
    This article should help you with developing and deploying your customised Firefox 4 installation (without touching the Windows 7 default user profile):
    http://mockbox.net/configmgr-sccm/174-install-and-configure-firefox-silently.html

  • How can I set a specific value for a field, according to the option selected in a previous drop-down menu?

    Eg.: I have a drop down menu with the following options: "1,2,3,4,5". What I want to do is the followin: If the option selected is "1" the field "Color" must be filled with "Green", if "2" the field color must be filled with "Red", etc

    You can use something like this as the custom calculation script of the color field:
    var v = this.getField("Dropdown1").valueAsString;
    if (v=="1") event.value = "Green";
    else if (v=="2") event.value = "Red";
    // etc.
    else event.value = "";

  • How can i download extension updates as files, to install on another computer?

    Installed FF on my wife's work computer, in our gradeschool library. The network that she is connected to allows FF to be updated, but blocks extension updates. How can i download extensions as files, to a stick at home, to update her computer? Extensions used are AdBlock+, TabMix+, NoScript, ForecastFox, checkCompatability, and (since FF29) Classic Theme Restorer.
    Both machines running Win7; FF28 at home, FF29 in the library.

    hello kthompsn, you can right-click the '''+ add to firefox button''' button on addons.mozilla.org & select "save target as...".
    <br>then you will end up with a .xpi file that you can put on a memory stick and install on the target pc by dragging the file into an open firefox window.

  • How can I set a file to hidden

    Hi all
    How can I set a file to hidden from within Java.
    This is what I have tried so far but with out any luck
        String[] cmd = new String[3];
        cmd[0] = "cmd.exe";
        cmd[1] = "attrib +h";
        cmd[2] = "\""+"C:/program files/Licence.xml"+"\"";
        Runtime rt = Runtime.getRuntime();
        Process proc = rt.exec(cmd);Thanks
    Craig

    Try
    cmd[0] = "attrib"
    cmd[1] = "+h"
    cmd[2] = "C:\Program Files\Licence.xml"
    You may need to double the baskslashes
    Is the spelling of "Licence" correct?

  • How can i set a path for my deployment files in weblogic server 10.3

    Hi
    How can i set the path for my WAR ,JAR files while deploying.i am using the wls10.3 version.
    is there any scripts for this ,please provide me.
    my Application is ADF 11g application.

    By "path", I assume you mean "classpath".
    The simplest way is simply to include the jars you need inside the web application or web module's WEB-INF/lib directory, EJB module's META-INF/lib directory, or EAR lib directory.
    If that's not practical, if you use NodeManager to start your servers, you can go to the "Server Start" tab in the server definition in the WebLogic console and edit the "Classpath" field, which defaults to no value. You can specify a classpath value there. Note that if you specify a value there, it REPLACES the default classpath for the server, it doesn't add to it. If you need to just add to it (a much more likely scenario), if the value references the value "$CLASSPATH" in it, that will reference the original classpath value that the server would have had.
    So, for instance, if you wanted to include the MQ jars in the server classpath, you could set a value like this:
    /usr/java/mq/lib/mq.jar:/usr/java/mq/lib/mqstuff.jar:$CLASSPATH

  • How can I set up cross fade to automatically trim files ?

    How can I set up cross fade to automatically trim the two files to size when fading between them? Thanks

    Hi, thanks for the reply. What I meant was that in Pro Tools, you can highlight an area between two tracks and crossfade. Then the files are exactly trimmed automatically so there is no excess overlap of the edges of both files. In Logic it seems to leave the overlap, and this can be a problem when you accidently click the wrong place and the underlying file is bought to the front, changing the crossfade area. I wish it to trim the excess so there is no danger of the lower file edges coming forward.

  • What is .PESVWSH file & how can I recover my previous file extension?

    Dear Sir,
    I have facing trouble opening any file. all file has convert automatically to .pesvwsh extension. After rename this file and try to open but not open and showing "the file can not be opened because there are problems with the content."
    Please help me how can i recover my all files and let me what is the pesvwsh file.
    Thanks & Best regards,
    Md. Anisur Rahman

    Hello,
    The 'Suggestions and Feedback for the Forums' forum is to give users a voice on Forums. Users can give suggestions for improvements or vote up suggestions and know that the Forums team is listening.
    I'd ask in the Virus and Malware forum on Microsoft Community, or the
    Windows forum on Microsoft Community.
    As the Microsoft Community is on a different platform, we cannot move the question for you.
    Once there, click on Participate near the top of the screen, and select 'Ask a Question' or 'Start a Discussion':
    Karl
    When you see answers and helpful posts, please click Vote As Helpful, Propose As Answer, and/or Mark As Answer.
    My Blog: Unlock PowerShell
    My Book:
    Windows PowerShell 2.0 Bible
    My E-mail: -join ('6F6C646B61726C406F75746C6F6F6B2E636F6D'-split'(?<=\G.{2})'|%{if($_){[char][int]"0x$_"}})

  • How can I set the maximum number of restarts for my PDF files?

    I want sent my PDF to a friend,but I just allow him see it only twice.
    How can I set the maximum number of restarts for my PDF files?
    My software edition is Acrobat X

    In the old days when PDFs were only opened on desktops and only in Acrobat or Reader, scripting could fake security features and people were generally convinced. As there are so many ways to open a PDF without scripts ever being run (from mobile devices to in-browser display, or simply opening the file in Illustrator), none of that works anymore.

  • How can i set the dos can compile and excute the jar file?please help?

    How can i set the dos prompt can compile my .java file and execute my jar file.

    Go to where you downloaded your Java SDK. Look around for a button labled "Installation." Click the button. Download the installation instructions. Read them. Then read them again.

  • HT4623 How can u set up your iphone when all the files are deleted?

    How can I set up my iphone if all the files are deleted?

    What files are deleted?
    Please explain

  • How can I set up a guest WiFi network using Time Capsule and Airport Express extension?

    How can I set up a guest WiFi network using Time Capsule and Airport Express extension?

    Sorry, but it is not possible to "extend" the Guest Network using either wireless or an Ethernet connection.

Maybe you are looking for

  • Installing Microsoft Office on MacBook Pro

    Hello, I recently purchased a late 2011 15' MacBook Pro with 4 gb of ram and would like to purchase the 2011 Microsoft Office Suite for Mac, which is 3 gb.  If i download the suite, will my MacBook Pro slow down significantly as a result, or just occ

  • Union All Function

    HI All, I am trying to make one query in wich i want territory wise sales report but i want to reflect it as territory 1 and its total than territory 2 and its total will union function will give me that result. So need help. Thanks- Mona

  • Matchcode to search files

    Hi, In my dynpro I have a "text box" to enter a name of a file. How can I add a matchcode to this "text box" so as to I can select a file ?  (I want to see the typical window to select a file). Thanks

  • URLConnection question..how to increase performance?

    Hi, I am trying to download a text file using FTP and display it in the browser. The code below is within a JSP page. My problem is that it works with small files very quickly, but as soon as the file size is large, it is VERY VERY slow. A file which

  • Flash Videos are being Cut!!(youtube,niconico,others)

    When i open a video in youtube or any other page to watch videos, my video seems to be cut like a 1/4th of what it should be and also when i right click on the video, the options menu are displayed at another area(like 50 pixels right and down of whe