JFileChooser and FileFilters

I have the following problem:;
I have a JFileChooser and I attached a FileFilter to it, which only allows files with the extension *.in and *.inx. Everything works well - only files with these extensions are shown in the Dialog.
But as a user I expect, that it is not a fault if I only type in the name of the file, because I expect the programme to add the extension automatically. For example in an OpenDialog, the user sees the file test.inx and the types in "test", because he/she thinks that the extension will be added.
This is not the case...and which is even worse, the call of fileChooser.getSelectedFiles() will return an empty array. Hence there is no possibility for the programme to add the file extension.....
How can solve this problem?? What is my mistake?? I cannot image that Swing is not able to do this, because this common FileDialog behaviour....
I thank everybody who tries to help me...

The quick and dirty workaround would be to create a "Save" dialog (setDialogType method), set the Button texts to whatever you want, the same for title. When the dialog returns, you can check the file (getSelectedFile()), and if it does not exist, try the same name with the extension(s).

Similar Messages

  • JFilechooser and droptarget

    Hi,
    I've managed to be able to drop files into a jfilechooser (using droptarget), but the drop somehow targets the wrong part of jfilechooser
    new DropTarget( jFileChooser, this);
    When I try the above, the drop only works on the scrollbar of jFileChooser (I can drop stuff on the scrollbar, but not in the file window). Do I need to target a sub-component of jFileChooser with DropTarget, if so how?
    Cheers,
    Daniel

    Don't know if it is the best way, but since I couldn't tell which sub-component of JFilechooser to use, I iterated through the JFilechooser and attached drop targets to all components within. Looks like it solved the problem.

  • JFileChooser and FilePermission write

    Hi,
    I use a JFileChooser in a swing application like this :
    JFileChooser fileChooser = new JFileChooser();
    fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    if (fileChooser.showOpenDialog(MainJWS.this)== JFileChooser.APPROVE_OPTION) {
    dir2Name = fileChooser.getSelectedFile().getPath();
    I want the application to only get rights on FilePermission to read. So I change my policy file like this :
    grant {
    permission java.io.FilePermission "<<ALL FILES>>", "read";
    So when the appli runs, there is a PermissionException on write right. Is there any way to use the JFileChooser only on a read mode ?
    thanks.

    Thanks, I saw it.
    Maybe there 's another way, with FileDialog ? Or with JFileChooser and FileSystemView ?
    any idea ?

  • Using jFileChooser and FileFilter

    I am using a jFileChooser and want to add a file filter to only show .jpg files. I tried using...
    FileFilter filter = new FileFilter();
    filter.addExtension("jpg");
    filter.setDescription("JPG Images");
    fileChooser.setFileFilter(filter);
    fileChooser.showSaveDialog(jPanel1)I get an error saying FileFilter is an abstract. I was wondering how I can successfully filter a jFileChooser. Also, what imports libraries do I need to perform the task. I have looked at sample code and it seems they do their own classes, I want to know how to handle this task using the libraries java provides.

    Here's another way to do it, using an anon. inner
    class:
    JFileChooser chooser = new JFileChooser();
    chooser.setFileFilter(new FileFilter() {
    public String getDescription() { return "Image
    files"; }
    public boolean accept(File f) {
    if(f.isDirectory()) return true;
    if(f.getName().endsWith(".jpg")) return true;
    if(f.getName().endsWith(".png")) return true;
    return false;
    /code]
    I find myself using a lot of anon. inner classes in
    Swing.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Problem with JFileChooser and ImageIcon

    I'm trying to create an ImageIcon object from file selected in JFileChooser. The problem is that jfc.getSelectedFile().getAbsolutePath() returns a string with backslashes and the constructor of ImageIcon requires the string to have slashes. I`ve tried to create it via URL but it doesn't work as well...
    String lastUsedPath;
    URL imageURL;
    JFileChooser fc = new JFileChooser();
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    int returnVal = fc.showDialog(frame,title);
    if(returnVal==JFileChooser.APPROVE_OPTION){                    
         lastUsedPath = fc.getSelectedFile().getAbsolutePath();
         imageURL = getClass().getResource(lastUsedPath);     //don't really get this but I copied it from Java Swing Tutorial          
    }else{
         return null;
    int curH, curW;            
    ImageIcon srcIcon = new ImageIcon(imageURL);                              
    curW = srcIcon.getIconWidth();
    curH = srcIcon.getIconHeight();If I use it this way imageURL is set to null.
    If I set the imageURL as 'fc.getSelectedFile().toURL()' the string is eg.: "file:/E:/file.jpg" instead of "E:/file.jpg". After that the ImageIcon is created but width and height return -1.
    If I try to create ImageIcon by 'new ImageIcon(lastUsedPath)' I get a not null object but the width & height of the ImageIcon is -1 as well.
    What do I have to do to be able to create an ImageIcon from file selected in JFileChooser? Why is this so hard and mind blowing?

    It still returns the ImageIcon object with width & height set to -1.
    EDIT:
    Got it finally:
    lastUsedPathForStupidImageIcon = fc.getSelectedFile().getPath();     
    img = ImageIO.read(new File(lastUsedPathForStupidImageIcon));
    curH = img.getHeight(this);
    curW = img.getWidth(this);The key was to use another String variable and hold the path instead of the absolute path
    Edited by: Beholder on Jan 17, 2010 1:35 PM

  • Problems with JFileChooser and Windows 2000 (can't see mydocuments contents

    Hi! I've an applet which has a JFileChooser component. In other Windows, I can select the MyDocuments folder and it goes there and list all the contents OK. But, in Windows 2000, when I go to MyDocuments, none of the contents is listed in the file chooser. I need to navigate through all the directories to get there (C:\documents and settings\user\my documents) and then, it shows its contents, but obviously, I don't want it to be this way because is difficult for the common user.
    Any idea of why is going on this?
    Thanks in advance!

    Hello, You need to use something like o=isp as the
    root DN, then o=yourorg.com goes beneath it.
    i.e.
    For the other questions on setup, just choose o=isp
    as base DN when you set up the directory server. When
    you run ims_dssetup.pl, choose o=internet as the DC
    tree base, then choose o=isp as the user/groups base
    suffix.
    When you are installing messaging server it will ask
    where to put the default organization, this is where
    you would choose o=abc.com, o=isp
    For more info on how this structure works please take
    a look at this link and it will all fit into place:
    http://docs.sun.com/source/816-6017-10/changes.htm#170
    8Alright, I got ims_dssetup to run successfully. But now when the ims 5.2 installation is about 50% done, I get the message:
    A serious problem occurred while installing the iPlanet Messaging Server Messaging SIE entry in LDAP (msg.cfgldap.sie.inf). It reported the following problem:
    The server configuration for the Messaging SIE entry in LDAP (msg.cfgldap.sie.inf) cannot be created.

  • JFileChooser and Read Only Folders in XP

    The following question concerns a Java application, not a applet or web service.
    If you are browsing a folder with JFileChooser the button to create a new folder is disabled if the parent folder is read-only. Under XP folders often show up as read only and cannot be easily changed by the user. Even if Windows reports that the parent folder is read only, it does not block the creation of sub-folders in it. I'd like to always make the create folder button active regardless of whether the parent folder is read only or not; that more truely reflects the folder creation permissions anyway and mimics the behaviour of an MFC file browser. How would I do this?
    I've even tried to add a listener to the file chooser so that as the user browses to a new directory I automatically change the write permissions of folder, but short of a system command, there's no way to change the write permissions from JAVA so I don't consider this a neat solution.
    I'm surprised that I haven't found similar complaints on the net. If you use a MFC file browser the create folder button is active, but a Java file chooser has it disabled for the same folder.
    Please help.

    What would you say to a new FileChooser? I love java but I'm no fan of Sun's choosers. (See www.MartinRinehart.com, Examples, ColorChooser.)
    Email me if you're interested in doing one.

  • JFileChooser and the filename

    Hi All,
    I'm going for 11 new things learned today about Java!
    I'm using JFileChooser to prompt for a file, and I need to capture the filename and see if it's inside the file.
    I'm getting a "found int, expected boolean" compile error. Can comeone enlighten?
    Thanks!
    MVP
    String strFileName;
    JFileChooser jfc = new JFileChooser();
    strFileName = jfc.getSelectedFile().getName();  // tried both these
    strFileName = jfc.getName(); // lines
    currentLine = strInFileArray;
    if(currentLine.indexOf(strFileName)) //compile error on this line

    I didn't say it didn't compile, it does compile.
    And I know it doesn't do anything because I display
    currentLine before and after the change is attempted.
    And I did read up on the method - how do you think I
    found it in the first place?If you did, then what does it say after the word "Returns" in the method description? And where else could you have found the method? Some IDEs will spit out a list of possible methods that can be called from an option. One of the reaosns why I suggest new comers shouldn't use IDEs to start (forces them to learn about the API which is the best possible thing for someone in your (ie newbie, nothing personal) possition to do).
    >
    Now, if statements like
    i++
    setBackground(Color.WHITE)
    setFont(myfont)
    getContentPane().setLayout()
    repaint()
    and others (iow, no '=' for assignment)
    all change objects or attributes of objects, it seems
    a logical assumption to me that
    currentLine.replaceAll(strFileName,NEW_FILE_NAME);
    will change the object 'currentLine'.So you assume that all methods work the sae way, and forget the docs? The first sentance of the second paragraph in the String API says:
    "Strings are constant; their values cannot be changed after they are created. "
    So you see, the answer to your question, and the why it is the way it is, are both in the API.
    >
    Finally, (not for you jverd, you are polite), to be
    called names by supposedly mature posters on this
    forum - which exists specifically for beginner-level
    questions like mine - is just amazing. Excuse me for
    thinking I might find help and assistance instead of
    abuse.A double standard, yes? I have to be mature, but not you? You whine alot. You can ask questions without whining, others do it all the time (you didn't whine in the first question in this thread, and I tried to answer (well, tried to get you to answer yourself, which I believe is more beneficial)). Once you started your whining again, I became immature also. No apologies here.
    And even if the assinine (which it was intentionally) it still had some help (by pointing to the API). You saw the API before (which is good) but I did not know that, and your questions seemed to indicate otherwise.
    >
    TheReallyDisappointedMVPBuck up. Nothing personal. Just ask questions differently, that's all.

  • Selecting all files from JFilechooser and renaming them??

    dear all
    i am working on a application that selects the jpeg,jpg,jpe files form the jfilechooser with an additonal botton rename which calls the rename method and the selected file is renamed.
    i have been succssful in mselecting one file and renaming it.but the problem is with...
    1) Selection of multiple files and sending their names and parent directories getParent(); is not working with taht....should i use arrays to store that .....but how when i have enabled multiple selection already.
    2)SEcond problem is to refersh the contents of JFileChooser after i have renamed it.iwant that it shopuld be refreshed automatically just after renaming has been done.
    help is always appreciated..
    regards
    s m sharma (trainee s/w/ engg)

    hi everybody
    i have done it myself.......it was not too tough that u didnot responed...anyway thanks..
    regards
    s m sharmna

  • JFileChooser and security

    Has anybody got the JFileChooser to open the user.dir or user.home directory? [I have used JFileChooser(".")] I have used the policytool to generate a policy file and also have tried to follow Irene's 10 steps to signing an applet but non have worked. I keep getting the security exception thrown that access denied to user.home or user.dir. Does anybody have an example policy file and a snippet of the JFileChooser code they used to open the local file system without getting a security exception throw? Any help would be much appreciated!
    Thank you in advance,
    dave

    The Notpad demo uses the JNLP api to read and write files. The api doc can be found at:
    http://java.sun.com/products/javawebstart/docs/javadoc/index.html
    Although the Notpad demo source is not available, there is other sample code available at:
    http://developer.java.sun.com/developer/releases/javawebstart/
    Included here is the webpad demo, which uses the FileOpenService and
    FileSaveService API's.

  • JFileChooser and remote filesystems

    I want to add(among local file system) a few remote filesystems to JFileChooser ,
    I implemented FileSytestemVIew(FileSystem) and File(RemoteFile) class.
    At the first glance everything looks ok - i can see local folders and remote root folder(in combo box), when i choose remote root i can see remote folders and files, but when i invoke double click to enter remote folders, exception occurs.
    for some reason JFileChooser sees 'ordinary' File - not my RemoteFile, and it treats it as a file (not folder) and wants to open it (approveSelection fires)
    Probably i did not implemented all the methods that are used ..
    Any ideas ? maybe there are some other ways to explore remote filesystems ?
    package pl.edu.pw.browser;
    import javax.swing.filechooser.FileSystemView;
    import java.io.File;
    import java.io.IOException;
    import pl.edu.pw.fileserver.client.Client;
    import java.util.*;
    import javax.swing.Icon;
    public class FileSystem extends FileSystemView {
    public FileSystem(ArrayList servers) {
    this.servers=servers;
    public File createFileObject(File dir, String filename) {
    System.out.println("createFileObject1");
    if (dir instanceof RemoteFile )
    return new RemoteFile(((RemoteFile)dir).getFtp(),dir.getAbsolutePath(), filename);
    return super.createFileObject(dir,filename);
    public boolean isDrive(File dir)
    if (dir instanceof RemoteFile )
    return false;
    return super.isDrive(dir);
    public boolean isFloppyDrive(File dir)
    if (dir instanceof RemoteFile )
    return false;
    return super.isFloppyDrive(dir);
    public boolean isComputerNode(File dir)
    if (dir instanceof RemoteFile)
    if(servers.contains(dir))
    return true;
    else
    return false;
    return super.isComputerNode(dir);
    public File createFileObject(String path) {
    return null;
    public boolean isFileSystem(File f) {
    System.out.println("isFileSystem");
    if (f instanceof RemoteFile) {
    return false;
    } else
    return super.isFileSystem(f);
    public boolean isFileSystemRoot(File dir)
    System.out.println("isFileSystemRoot");
    if (dir instanceof RemoteFile)
    if(servers.contains(dir))
    return true;
    else
    return false;
    return super.isFileSystemRoot(dir);
    public boolean isRoot(File f) {
    System.out.println("isRoot");
    if (f instanceof RemoteFile )
    if(servers.contains(f))
    return true;
    else
    return false;
    return super.isRoot(f);
    public String getSystemTypeDescription(File f)
    if (f instanceof RemoteFile)
    return f.getName();
    return super.getSystemTypeDescription(f);
    public Icon getSystemIcon(File f)
    return super.getSystemIcon(f);
    public boolean isParent(File folder,
    File file)
    if (folder instanceof RemoteFile && file instanceof RemoteFile )
    System.out.println("isParent("+folder.getAbsolutePath()+")("+file.getAbsolutePath()+")");
    if(file.getParent().equals(folder.getAbsolutePath()))
    System.out.println("is");
    return true;
    else
    return false;
    return super.isParent(folder,file);
    public File getChild(File parent,
    String fileName)
    System.out.println("getChild");
    if (parent instanceof RemoteFile )
    return new RemoteFile(((RemoteFile)parent).getFtp(),parent.getAbsolutePath(),fileName);
    return super.getChild(parent,fileName);
    public File createNewFolder(File containingDir)
    throws IOException {
    System.out.println("createNewFolder");
    if (containingDir instanceof RemoteFile )
    return null;
    return new File(containingDir,"/nowyFolder");
    public String getSystemDisplayName(File f)
    if (f instanceof RemoteFile )
    return f.getName();
    else
    return super.getSystemDisplayName(f);
    public File[] getRoots()
    System.out.println("getRoots");
    File[] files = super.getRoots();
    File[] fileAll = new File[files.length+1];
    int i=0;
    for(i=0;i<files.length;i++)
    fileAll=files[i];
    fileAll[i]=createFileSystemRoot((RemoteFile)servers.get(0));
    return fileAll;
    public boolean isHiddenFile(File f) {
    return f.isHidden();
    public File getParentDirectory(File dir) {
    System.out.println("getParentDirectory");
    if (dir instanceof RemoteFile)
    String p = dir.getParent();
    if(p!=null)
    return new RemoteFile(((RemoteFile)dir).getFtp(),p);
    else
    return null;
    else
    return super.getParentDirectory(dir);
    protected File createFileSystemRoot(File f)
    System.out.println("createFileSystemRoot");
    if (f instanceof RemoteFile)
    return new FileSystemRoot( (RemoteFile) f);
    else
    return super.createFileSystemRoot(f);
    static class FileSystemRoot extends RemoteFile {
    public FileSystemRoot(RemoteFile f) {
    super(f.getFtp(),f.getAbsolutePath());
    public File[] getFiles(File dir, boolean useFileHiding) {
    if (dir instanceof RemoteFile)
    RemoteFile[] files = (RemoteFile[])( (RemoteFile) dir).listFiles();
    return files;
    else
    return dir.listFiles();
    public File getHomeDirectory() {
    return super.getHomeDirectory();
    ArrayList servers = null;
    package pl.edu.pw.browser;
    import java.io.File;
    import java.io.FilenameFilter;
    import java.io.FileFilter;
    import pl.edu.pw.fileserver.client.Client;
    import java.util.*;
    import java.text.*;
    import pl.edu.pw.fileserver.Constants;
    public class RemoteFile extends File {
    final static char PATHDELIMS = '/';
    public final static String absoluteStart = "//";
    public RemoteFile(Client ftp, String parent) {
    super(parent);
    this.ftp = ftp;
    path = parent;
    public RemoteFile(Client ftp, String parent, String name) {
    this(ftp, parent);
    if (path.length()>0 && path.charAt(path.length()-1) == PATHDELIMS)
    path += name;
    else
    path += PATHDELIMS + name;
    public boolean equals(Object obj) {
    if (!checked)
    exists();
    return path.equals(obj.toString());
    public boolean isDirectory() {
    if (!checked)
    exists();
    return isdirectory;
    public boolean isFile() {
    if (!checked)
    exists();
    return isfile;
    public boolean isAbsolute() {
    if (!checked)
    exists();
    return path.length() > 0 && path.startsWith(this.absoluteStart);
    public boolean isHidden() {
    if (!checked)
    exists();
    return ishidden;
    public long lastModified() {
    return modified;
    public long length() {
    return length;
    public String[] list() {
    return list(null);
    public String[] list(FilenameFilter filter) {
    System.out.println("list");
    String[] result = null;
    try{
    ArrayList names = (ArrayList)ftp.dir(this.getAbsolutePath());
    ArrayList files = new ArrayList();
    for(int i=0;i<names.size();i++)
    RemoteFile rf = new RemoteFile(ftp,(String)names.get(i));
    if (filter == null || filter.accept(this,rf.getName()))
    files.add(rf.getName());
    result = new String[files.size()];
    files.toArray(result);
    catch(Exception ex)
    ex.printStackTrace();
    return result;
    public File[] listFiles() {
    FileFilter filter = null;
    return listFiles(filter);
    public File[] listFiles(FileFilter filter) {
    System.out.println("listFiles");
    RemoteFile[] result = null;
    try{
    ArrayList names = (ArrayList)ftp.dir(this.getAbsolutePath());
    ArrayList files = new ArrayList();
    for(int i=0;i<names.size();i++)
    RemoteFile rf = new RemoteFile(ftp,(String)names.get(i));
    rf.exists();
    if (filter == null || filter.accept(rf))
    files.add(rf);
    result = new RemoteFile[files.size()];
    System.out.println("listFiles.size="+files.size());
    files.toArray(result);
    catch(Exception ex)
    ex.printStackTrace();
    return result;
    public String getPath() {
    return path;
    public String getCanonicalPath() {
    return getAbsolutePath();
    public String getAbsolutePath() {
    if (!isAbsolute()) {
    return ftp.pwd();
    return path;
    public String getName() {
    String result=path;
    if(result.charAt(result.length()-1) == this.PATHDELIMS)
    result = result.substring(0,result.length()-1);
    int i = result.lastIndexOf(this.PATHDELIMS);
    if(i!=-1)
    result = result.substring(i+1);
    return result;
    public String getParent() {
    String result=path;
    if(result.charAt(result.length()-1) == this.PATHDELIMS)
    result = result.substring(0,result.length()-1);
    int i = result.lastIndexOf(this.PATHDELIMS);
    if(i<3)
    return null;
    result = result.substring(0,i);
    return result;
    public boolean exists() {
    boolean ok = false;
    try {
    String r = ftp.exists(path);
    if(r != null)
    System.out.println("('"+path+"')header:"+r);
    ok = true;
    StringTokenizer st = new StringTokenizer(r,Constants.HEADER_SEPARATOR);
    String answer = st.nextToken();
    if(answer.equals(Constants.TRUE))
    isfile=true;
    isdirectory=false;
    answer = st.nextToken();
    if(answer.equals(Constants.TRUE))
    canread = true;
    answer = st.nextToken();
    if(answer.equals(Constants.TRUE))
    canwrite = true;
    answer = st.nextToken();
    if(answer.equals(Constants.TRUE))
    ishidden = true;
    answer = st.nextToken();
    length = Long.parseLong(answer);
    if(isfile)
    answer = st.nextToken();
    modified = Long.parseLong(answer);
    checked = true;
    catch (Exception ex) {
    ex.printStackTrace();
    return ok;
    public boolean canRead() {
    return canread;
    public boolean canWrite() {
    return canwrite;
    public int hashCode() {
    return path.hashCode() ^ 098123;
    public boolean mkdir() {
    return false;
    public boolean renameTo(File dest) {
    return false;
    public Client getFtp() {
    return ftp;
    private Client ftp;
    private boolean checked = false;
    private boolean isdirectory = true;
    private boolean isfile = false;
    private boolean ishidden = false;
    private boolean canread = false;
    private boolean canwrite = false;
    private String path;
    private long length = 0;
    private long modified =0;
    java.lang.NullPointerException
         at pl.edu.pw.browser.Browser.openLocalFile(Browser.java:136)
         at pl.edu.pw.browser.component.FileChooser.approveSelection(FileChooser.java:31)
         at javax.swing.plaf.basic.BasicFileChooserUI$DoubleClickListener.mouseClicked(BasicFileChooserUI.java:412)
         at java.awt.AWTEventMulticaster.mouseClicked(AWTEventMulticaster.java:208)
         at java.awt.AWTEventMulticaster.mouseClicked(AWTEventMulticaster.java:207)
         at java.awt.Component.processMouseEvent(Component.java:5137)
         at java.awt.Component.processEvent(Component.java:4931)
         at java.awt.Container.processEvent(Container.java:1566)
         at java.awt.Component.dispatchEventImpl(Component.java:3639)
         at java.awt.Container.dispatchEventImpl(Container.java:1623)
         at java.awt.Component.dispatchEvent(Component.java:3480)
         at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3450)
         at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3174)
         at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3095)
         at java.awt.Container.dispatchEventImpl(Container.java:1609)
         at java.awt.Window.dispatchEventImpl(Window.java:1590)
         at java.awt.Component.dispatchEvent(Component.java:3480)
         at java.awt.EventQueue.dispatchEvent(EventQueue.java:450)
         at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:197)
         at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
         at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:144)
         at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:136)
         at java.awt.EventDispatchThread.run(EventDispatchThread.java:99)

    i solve the problem .
    I did not overwrite File.getConicalFile() , this method is invoked at javax.swing.plaf.basic.BasicFileChooserUI$DoubleClickListener.mouseClicked(BasicFileChooserUI.java:412)
    that is why i recived a new object type File when I was waiting for RemoteFile

  • JFileChooser and date format questions

    I have a JFileChooser that currently works - I set the default directory and allow the user to select a file or enter a file name.
    I have been asked to modify this to prepopulate the file name field on the JFileChooser.
    How do I do that? It is not obvious which method to call to set the filename field.
    Also, the file name needs to be a timestamp "*yyyyMMddHHmmss*.dat"
    I tried creating the timestamp part with the following code, but it does not format as expected.
            String s = "";
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddddHHmmss");
            try
                java.util.Date now = new java.util.Date();
                java.util.Date dat = dateFormat.parse( now.toString() );
                s = dat.toString();
            }What is wrong with this?
    Thanks.

    I don't do Swing and this is also not the subforum for Swing questions. It has its own subforum.

  • JFileChooser and My network Places??

    Hello all,
    In the Filename of JFileChooser if i type \\100.100.100.100 or even \\100.100.100.100\d$ and click on open button it should ask the username and password of that pc and on appropriate combination of username and password it should show the list of the folder and file of that PC.
    How to get this?what is the code that is to be written in the open button event?
    Thank you,
    Ramesh shrestha

    I am running XP home with SP3.  click on start then my network place.  You should see different folders from your other computers and your router.  On the left  it should show either show or hide icons for network upnp.  If you are seeing the icons for lan and wireless and gateway then your computer settings are not setup properly.
    Right-click on start then click on properties  Click on customise then advance.  Go down to Network Connections set settings to display as connect to menu.
    Greetings from Northern Ontario, Canada

  • JFileChooser and links .lnk

    Hi. I'm having a problem with JFileChooser. When I try to click on a shortcut I get the file .lnk selected instead of the directory to it associated.
    Do you know how can I do this task?
    Alternatively I could use FileDialog..but, does it support Multiple Selection?
    Thanks very very much,
    Albert

    Hi ,
    use the class sun.awt.shell.ShellFolder
    the files are selected by the JFileChooser is a sun.awt.shell.ShellFolder
    sun.awt.shell.ShellFolder is a sub class of File
    This class contains a method isLink() , getLinkLocation() it will helps to
    get the link associated. I give the sample code and listen the actionPerformed
    method
    import java.awt.* ;
    import java.awt.event.* ;
    import java.io.* ;
    import javax.swing.*;
    import sun.awt.shell.ShellFolder;
    public class FCTest extends JFrame {
        public FCTest() {
            setTitle( "File Chooser Test" ) ;
            setDefaultCloseOperation( EXIT_ON_CLOSE ) ;
            init() ;
            setSize( 400 , 300 ) ;
            setVisible( true ) ;
        private JFileChooser fc ;
        private void init() {
            fc = new JFileChooser() ;
            fc.setMultiSelectionEnabled( true ) ;
            getContentPane().add( new JButton( new ButAct() ) , BorderLayout.SOUTH ) ;
        public class ButAct extends AbstractAction {
            public ButAct() {
                super( "My Button" ) ;
            public void actionPerformed( ActionEvent actEvt ) {
                int r = fc.showOpenDialog( FCTest.this ) ;
                if( r != JFileChooser.APPROVE_OPTION )
                    return ;
                File[] files = fc.getSelectedFiles() ;
                for( int i = 0 ; i < files.length ; i++ ) {
                    if( files[i] instanceof ShellFolder ) {
                        ShellFolder sf = ( ShellFolder ) files[i] ;
                        if( sf.isLink() ) {
                            try {
                                System.out.println( sf.getLinkLocation().getPath() );
                            } catch ( FileNotFoundException fnfe ) {
                                System.out.println( "Invalid Link : " + files.getPath() );
    } else {
    System.out.println( files[i].getPath() );
    } else {
    System.out.println( files[i].getPath() );
    public static void main(String[] args) {
    SwingUtilities.invokeLater( new Runnable() {
    public void run() {
    new FCTest() ;

  • JFileChooser and thumbnail view

    How can I implement a custom JFileChooser that show thumbnail of image files such as TIFF and PNG?
    As before, I used FileDialog on Windows XP for this purpose.
    But FileDialog does not support multi file selection and file name filters.
    I tried to implement custom FileView. (getIcon() method).
    But it was so slow and strange.
    Could you guys give me a advice on this problem?

    Hi Dhiva,
    materialized view is essentially a table that is produced from other tables based on a query. It's results are physically stored in the database and are refreshed either when the user requests ('on-demand refresh') or after commit.
    A simple view is just a query stored in the database. It's results are not stored anywhere, they're calculated and returned to the user only when the view is queried.
    Best regards,
    Nikolay

Maybe you are looking for