Java JFileChooser getDriveDisplayName(File path)

Here you can find the source of getDriveDisplayName(File path)

Description

get Drive Display Name

License

Open Source License

Declaration

public static String getDriveDisplayName(File path) 

Method Source Code

//package com.java2s;
/**//  ww w  . j  a va2  s  .  c  om
* @(#)SysUtil.java
* 
* Copyright (2003) Bro3
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation; either version 2, or any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc., 59 Temple
* Place, Boston, MA 02111.
*
* Contact: bro3@users.sourceforge.net
**/

import java.io.File;

import javax.swing.filechooser.FileSystemView;

public class Main {
    public static String getDriveDisplayName(File path) {

        FileSystemView fsv = new javax.swing.JFileChooser().getFileSystemView();

        if (fsv != null) {

            File tmp = path;

            while (tmp.getParentFile() != null)
                tmp = tmp.getParentFile();

            String displayName = fsv.getSystemDisplayName(tmp);

            if (!displayName.trim().equals(""))
                return displayName;

            return "";
        }

        return null;
    }
}

Related

  1. directoryFetch(File starting)
  2. exportFile(JFileChooser fileChooser, String contents)
  3. fileChooser()
  4. getChoiceFileFromUser()
  5. getDir(String title, String initDir, boolean allowFiles, Component parent)
  6. getExtension(File f)
  7. getFile()
  8. getFile(Component parent, String title, boolean write)
  9. getFile(FileFilter filter)