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 767221
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T17:10:38+00:00 2026-05-14T17:10:38+00:00

i have this issue working but i would like to know if there is

  • 0

i have this issue working but i would like to know if there is a better way of adding the file extension?

what i am doing right now is:

String filePath = chooser.getSelectedFile().getAbsoluteFile() + ".html";

im adding the extension hard coded. and then saving to it.

just wondering if there is a more robust/logical manner this can be implemented?

thank you for your time.

EDIT: i ask this as i would like my app to be portable across platforms. so adding .html manually i may make this a windows only solution.

EDIT: i think ive surfed enough to know that .html hard coded is safe as i havent found any documentation that says dont take this approach (not completely sure).

ISSUE: also if i want to save the file in another format, text, for example how do i detect that the user selected which format?

FileNameExtensionFilter can add filters to the dialog but how do i get the return value for file type selected?

EDIT: i have studied this but still unclear how to retrive user selected file type.

EDIT: this is a rephrase of my issue:

alt text http://img98.imageshack.us/img98/4904/savef.jpg my question is how can i retrieve/find out which one of the two filters the user has selected as the save format. HTML or JPEG? how do i retrieve this info from JFileChooser? thank you.

EDIT: found something out: it has something to do with JFileChooser.getFileFilter()
your help still welcome.

EDIT: getFileFilter() and FileNameExtensionFilter comparasion solved this issue.

  • 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-14T17:10:38+00:00Added an answer on May 14, 2026 at 5:10 pm

    Here is the code snippet that solves the issue:

    JFileChooser chooser = new JFileChooser();
    chooser.setMultiSelectionEnabled(false);
    chooser.setAcceptAllFileFilterUsed(false);
    
    FileNameExtensionFilter filter = new FileNameExtensionFilter("HTML Documents", "htm", "html");
    chooser.setFileFilter(filter);
    
    int option = chooser.showSaveDialog(ChatGUI.this);
    if (option == JFileChooser.APPROVE_OPTION) {
        // Set up document to be parsed as HTML
        StyledDocument doc = (StyledDocument)textPaneHistory.getDocument();
        HTMLEditorKit kit = new HTMLEditorKit();
    
        BufferedOutputStream out;
    
        try {
            System.out.println(chooser.getFileFilter());
    
            if (chooser.getFileFilter() == filter)
                System.out.println("ha ha");
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I already have this issue but I cannot remember how to solved it. (I
Heyy can somebody help me ? i have this issue that still do know
I have this issue with ComboBox that uses IEnumerable<Brush> as ItemsSource; the problem lies
I have this issue, I'm have a user selected in LDAP through ldap search,
I have this exact issue ASP.net can’t update page from event handler and it's
I have this chronic issue with iPhone UI development where views sometimes seem to
I am having trouble with the following SQL statement. I have had this issue
I have been having this issue in iterating through an array of keys and
This is very odd. I have never had this issue with ShowDialog in C#.
Note: This issue appears to be limited to SQL Server 2005 SP2 I have

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.