Java Swing Tutorial - Java JFileChooser.getName(File f)








Syntax

JFileChooser.getName(File f) has the following syntax.

public String getName(File f)

Example

In the following code shows how to use JFileChooser.getName(File f) method.

//from  w  w  w .j a  va2s  .  c o m
import java.awt.BorderLayout;
import java.io.File;

import javax.swing.Icon;
import javax.swing.JFileChooser;
import javax.swing.JFrame;

public class Main{

  public static void main(String[] a) {
    JFrame frame = new JFrame("JFileChooser Popup");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JFileChooser fileChooser = new JFileChooser(".");
    
    String name = fileChooser.getName(new File("."));
    frame.add(fileChooser, BorderLayout.CENTER);

    frame.pack();
    frame.setVisible(true);
  }
}