Java JFileChooserJFileChooser is a class that is present in the java Swing package. The java Swing package is essential for JavaTM Foundation Classes(JFC). JFileChooser contains many elements that assist in building a graphical user Interface in java. Java Swing gives components like buttons, panels, dialogs, etc. JFileChooser is a simple and successful method for inciting the client to pick a file or a directory. JFileChooser inherited the properties of JComponent class and implemented them with an Accessible interface. Constructors Present in Java JFileChooser Class1. JFileChooser(): Constructs a JFileChooser highlighting the client's default directory. Example program on JFileChooser() Output: 2. JFileChooser(File currentDirectory): Constructs a JFileChooser involving the given File as the way. Example program on JFileChooser(File currentDirectory) Output: 3. JFileChooser(File currentDirectory, FileSystemViewfsv): Constructs a JFileChooser utilizing the given current catalog and FileSystemView. Example program on JFileChooser(File currentDirectory, FileSystemViewfsv) Output: 4. JFileChooser(FileSystemViewfsv): Constructs a JFileChooser utilizing the given FileSystemView. Example program on JFileChooser(FileSystemViewfsv) Output: 5. JFileChooser(String currentDirectoryPath): Constructs a JFileChooser utilizing the given way. Example program on JFileChooser(String currentDirectoryPath): Output: 6. JFileChooser(String currentDirectoryPath, FileSystemViewfsv): Constructs a JFileChooser utilizing the given current catalog way and FileSystemView. Example program on JFileChooser( String currentDirectoryPath, FileSystemViewfsv ): Output: 7. JFileChooser( File ): Example program on JFileChooser( File ) constructor: Output: 8. JFileChooser(File, FileSystemView): Example on JFileChooser( File, FileSystemView ) Output: Advantages of JFileChooser()
Methods in JFileChooser ClassThe JFileChooser class fundamentally gives three strategies that show the record chooser discoursed, as in the accompanying: 1. showOpenDialog(component owner ): This technique opens an exchange box that contains an endorsement button, as such, "Open", that opens a document from the discourse. Syntax: 2. showSaveDialog( component owner ): This strategy is utilized when the client needs to save the particular document that he/she is utilizing. This exchange box contains an endorsement button, as such, "Save", to save the document. Syntax: 3. showDialog(component owner, string): This technique shows an exchange box with an endorsement button which is client characterized. Syntax: 4. getSelectedFile(): This technique returns the document that is chosen by the client. Syntax: 5. setCurrentDirectory(File f): This technique sets the ongoing catalog as determined. Syntax: 6. getCurrentDirectory(): This technique for JFileChooser returns the ongoing index as chosen by the client. Syntax: 7. (File f):This strategy returns the name of the document as given by the record contention. Syntax: ExampleA example program to create a JFrame window: Output: Next TopicWhat is LINQ? |