Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7619095
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T03:34:17+00:00 2026-05-31T03:34:17+00:00

I have one problem in fileChooser. when fileChooser window come then I want to

  • 0

I have one problem in fileChooser.

when fileChooser window come then I want to show .java as a default name in “File of type” and in list I want to show *.java, *.class, All File respectively.

For this I use following code:

public class Main {
public static void main(String[] argv) throws ClassNotFoundException, InstantiationException, IllegalAccessException, UnsupportedLookAndFeelException {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
JFileChooser fileChooser = new JFileChooser(new File("."));
fileChooser.addChoosableFileFilter(new MyFilter());
fileChooser.addChoosableFileFilter(new MyFilter2());
fileChooser.setAcceptAllFileFilterUsed(true);
fileChooser.showOpenDialog(null);
System.out.println(fileChooser.getSelectedFile());
}
}

class MyFilter extends javax.swing.filechooser.FileFilter {
public boolean accept(File file) {
String filename = file.getName();
return filename.endsWith(".java");
}

public String getDescription() {
return "*.java";
}
}

class MyFilter2 extends javax.swing.filechooser.FileFilter {
  public boolean accept(File file) {
    String filename = file.getName();
    return filename.endsWith(".class");
  }

  public String getDescription() {
    return "*.class";
  }
}

but in this code by default nothing is there in “File of type” and in the list it show *.java, *.class, All File respectively.But I want to show *.java name as a default name in “File of type”.

When I change this code and put fileChooser.setAcceptAllFileFilterUsed(true); above to fileChooser.addChoosableFileFilter(new MyFilter()); then All File show defaule name in “File of type”.

If you save a text file in text editor then there Text Documents(.txt) show as a default and in list Text Documents(.txt) and All File is there.

I want same thing in my application.

I am also attaching photo which give clear information what I want:

My application work like this:

enter image description here

enter image description here

But I want like this:

enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T03:34:19+00:00Added an answer on May 31, 2026 at 3:34 am

    Customizing a JFileChooser might be worth looking at as it does exactly as you describe.

    The official JFileChooser documentation also covers your problem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have one problem , I want to get some data from XML file
I have one problem. i have dep. prop. of type List.. public const string
I have one problem , i want to refer particular file in my system
i have one problem I save my upload data in the blob file type
I have one problem with Javascript Nodes.I want to find out what button was
i have one problem with handling list,i have three class named as UserInf,userData,userProcess,i created
I have a file saved that works fine apart from one problem. When the
I am working on UISplitview base project.I have one problem regarding UISplitview.I want to
I have one problem in which i simply want to know how i can
I have one problem with my iOS Application. I want to play multiple audio

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.