How to determine which FileChooser ExtensionFilter has been selected

Hi,
I'm using a JavaFX fileChooser.showSaveDialog with two extension filters (*.csv and *.xml). How can I determine which filter was selected when the end-user clicks the save button?
I am writing a program that allows the end-user to create an output file in CSV or XML format.
If the end-user enters a file name with no extension, I need a way to determine if I should create a CSV or XML file. I would also like to add the proper extension to the file name if none is specified by the end-user. I want to do this based on which filter the end-user has selected. I wrote a Java program 5 years ago and I was able to do this with the following instruction:
String extension = jFileChooser.getFileFilter().getDescription();
I can't find a similar instruction for JavFX.
My JavaFX Code:
FileChooser fileChooser = new FileChooser();
fileChooser.setInitialDirectory(new File(options.getOutputDirectory()));
ExtensionFilter filter1 = new FileChooser.ExtensionFilter("Comma Delimited (*.csv)", "*.csv");
fileChooser.getExtensionFilters().add(filter1);
ExtensionFilter filter2 = new FileChooser.ExtensionFilter("XML Document (*.xml)", "*.xml");
fileChooser.getExtensionFilters().add(filter2);
File file = fileChooser.showSaveDialog(stage);
String filename = file.getAbsolutePath();...How do I determine which extension filter has been selected?
My Java Code:
JFileChooser jFileChooser = new JFileChooser();
jFileChooser.setCurrentDirectory(new File(outputDirectory));
jFileChooser.setSelectedFile(new File(backupfile));
FileFilter filter = new FileNameExtensionFilter("Comma Delimited (*.csv)", "csv");
jFileChooser.addChoosableFileFilter(filter);
jFileChooser.setFileFilter(filter);
filter = new FileNameExtensionFilter("XML Document (*.xml)", "xml");
jFileChooser.addChoosableFileFilter(filter);
jFileChooser.setAcceptAllFileFilterUsed(false);
jFileChooser.setDialogTitle("Export Alarms");
jFileChooser.setBackground(colorFileChooser);
int returnVal = jFileChooser.showDialog(jFrame, "Export");
if (returnVal == JFileChooser.APPROVE_OPTION) {
    File file = jFileChooser.getSelectedFile();
    String filename = file.getAbsolutePath();
    String extension = jFileChooser.getFileFilter().getDescription();
    if (extension.equals("XML Document (*.xml)")) {
        if (!filename.endsWith(".xml") && !filename.endsWith(".XML")) {
            filename = filename + ".xml";
        saveTableXML(filename);
    else if (extension.equals("Comma Delimited (*.csv)")) {
        if (!filename.endsWith(".csv") && !filename.endsWith(".CSV")) {
            filename = filename + ".csv";
        saveTableCSV(filename);
}Thanks,
Barry
Edited by: 907965 on May 13, 2012 1:14 PM
Edited by: 907965 on May 13, 2012 1:15 PM
Edited by: 907965 on May 13, 2012 1:19 PM

This problem is currently tracked as http://javafx-jira.kenai.com/browse/RT-18836.

Similar Messages

  • How do I know what item has been selected in a select list?

    I built a select list where the user selects one item from the list and then searches using the searchfield. I need to know what item has been selected in the select list so that I can do branching and branch the user to a particular page. Can someone tell me how I can accomplish this?
    So if I want to search for Tea in the drinks category I would need to click on Drink in the select list and then type "Tea" and select search. After that I get redirected to a table called "Drinks" and there the search results will be displayed. please help!

    I tried to mach expressions... I made a simple list(with redirection):
    STATIC:Yes;Y,No;N and it displays fine. I then try to do branching where exp1=exp2 Where I tried to have the label "X" for E1 and "Y" for E2 and nothing happened. I tried to use the name of the list Xlist and it failed too. I tried Request=exp1 and didnt work either. I set the source for the list as static. I am not sure what I am doing wrong. When i tried !=exp nothing happened either... perhaps the values I am using are wrong? Pleas help me out.

  • Which menu item has been selected?

    At runtime when a user selects a menu item in the portal that leads them into a Web Dynpro ABAP Application, I need to know which menu item they have selected. We have 2 menu items that use the same web dynpro ABAP application and need to know which one has been selected by the user. Can anyone help with this please?
    thanks,
    Malcolm.

    Malcolm Clark wrote:
    At runtime when a user selects a menu item in the portal.......We have 2 menu items that use the same web dynpro ABAP
    Are you talking about portal navigation nodes or something else?

  • How to determine which Windows application has focus

    I'm new to JAVA and new to programming. I hope someone will help me out. I'm trying to write a simple JLink program (JLink is a JAVA API for Pro|Engineer, a CAD design program). In part of this program I need to determine if Pro|E has focus. Is there some way to use JAVA to determine which actively running Windows application has focus?
    I basically want my program to pause when focus changes to another program. For example: While Pro|E is active and has focus the program runs, when I select an Excel window, or Outlook, or Notepad or any other window my program will pause until focus is returned. I just need to determine which window within Windows has focus.
    I hope I have explained this properly. I searched the internet for an answer but found nothing. I did come across some references to JNI, but I'm not sure what that is or how to use it.
    Thank you!

    I just need to determine which window within Windows has focus.No, you don't. All you need to determine is whether your application has the focus. If it doesn't, then some other application does, but it's really irrelevant which one does. All that's relevant is that your application doesn't have the focus and hence it should pause.

  • Recognize with ALV Instance has been selected.

    Hi everybody.
    I'm not sure how to perform the next situation:
    I'm working with two ALV Grid (OO) at the same time. I have defined an Exit Handler class to get the value of a field since a double-click perform. Obviously each ALV has an own fcat and data.
    Is it there a way to determine which ALV Instance has been double-clicked to get data just for its corresponding data table, or I shorld do it directly?
    Can I use a method such like cl_exithandler=>get_instance (obviously if there's one available?
    Cheers!!
    I would highly reward a good question.

    Do need to identify which instance.
    it will take u to the exact instance of the alv.
    I think u have written diffrent defination for different instance
    Make different Event reciever for different instance
    o_evt_rcvr1      TYPE REF TO lcl_event_receiver1. for first instance
    o_evt_rcvr2      TYPE REF TO lcl_event_receiver2. for first instance
    and raise Event for different instnace
    *Set the event handlers for first instance
      SET HANDLER o_evt_rcvr1->double_click FOR o_alvgrid1.
    *Set the event handlers for second instance
      SET HANDLER o_evt_rcvr2->double_click FOR o_alvgrid2.
    It will Take u to the Exact defination
    Message was edited by: Manoj Gupta

  • How to know which button has been selected on portal screen

    Dear Freinds,
                i an abaper i have one specific doubt regarding icon which has been selected on the portal screen.
    My requirement is we have portal screen on which i have two Buttons(or links) one Self and another for Dependents. i have to write an Bapi or RFC and give it to webdynpro developer.
    i have to write logic in my RFC based on the button selected on the portal screen (self or dependent) .
    in my RFC function module i have used import parameters &  table parameters( return value for the webdynpro to pick up)  . In the table parameters i have given structure z_struc  & the  Z_Struc has basically three fields
    a) self b) depndt c) flag.
    so i have written logic as
                       if v_flag_self = 'A'
                        logic for the self of the employee
                       elseif  v_flag_dep = 'B'.
                        logic for the dependent.
                       endif.
    so any one  could please let me know how i should pass on to the webdynpro
    or to recognize that the value for the Self he has to consider is A
    and dependent button he has to take is B. Because based ont he this flag values
    (A & B) only my logic works.
    how i should pass this values to him .
    Regards
    latha.

    Thanks!
    This wasn't there when I first looked at it, or I was looking at another location of the api, I will make sure to look at this one now :D.
    I basically did Action action = Dialog.show().
    then did if (action.equals(Dialog.Actions.OK))
    //code
    }So it works :).
    I like the custom action too, I'm interested in the example Action response = Dialogs.create()
          .title("You do want dialogs right?")
          .masthead("Just Checkin'")
          .message( "I was a bit worried that you might not want them, so I wanted to double check.")
          .showConfirm();I from the api it says that .create() is static Dialogs Type, so I'm curious how that's used as the Action in this case?
    Thanks again :)

  • How to find out the PO line items for which no GRN has been done

    Dear Friends,
    I need a report which will show all the fully open PO items for which no GRN has been done.
    In ME2N when I give the selection parameter "open goods receipt" then it shows all the line items with partially & fully open. But my requirement is to get a report of only fully open items.
    Regards
    Rutabhadra Panda

    Hi Friends,
    Thanks a lot for your reply.
    But this is a report which projects the expected GRNs & does not depend whether partial or full.
    Is there any other way out?
    Can  I download from the table directly.
    Regards
    Rutabhadra Panda

  • How to determine which chipset my Satellite L300/700 has?

    I have a SATELLITE L300/700 (PSLB8A-047004). The User Guide covers several models. It indicates that the chipset determines which memory modules I need for a memory upgrade. How do I find out which chipset I have, please?
    Kev.

    > I'm still curious about how to determine which chipset I have - any thoughts?
    Go to the device manger and click on IDE Ata/Atapi controllers:
    http://img814.imageshack.us/img814/7321/chipset.jpg
    There you will see your chipset installed on your laptop. In my case, as shown on the screenshot is Intel ICH9m

  • How do i know if row has been updated?

    Hi
    Please can someone guide me on how I can determine if my update has been successful. I am currently using the method below but my data is being put into the table but the method rowUpdated() returns false when it should return true.
    rs.moveToInsertRow();
    rs.updateString("SL_Name", "Antek")
    rs.insertRow();
    System.out.println("Row updated " + rs.rowUpdated());
    Thanxs
    Antek

    I am using a primary key which is set by ms-sql server and it has the properties not-null auto incrementing. I was using the manual insert function before but then I realised the moveToInsertRow() method so I changed because of the added benefits to my program I can get. Before I was using the following code to see if a row was inserted see below. (I want something similar for the new way I insert data into table please)
    ======
    what i use to use before
    ======
    int numRows= myStatement.executeUpdate(sql);          
    System.out.println(numRows + " rows updated");
    if (numRows > 0)
    returnString = "success";
    Antek

  • Best way to determine what objects has been selected in a Collection?

    Hi all
    I´m currently developing an application where a user can create a PDF based on the choices made from multiple collections.
    Each collection contatins 10-50 items, and there are about 8 different collections with objects.
    Checkboxes are used to select items from these collections.
    I´m wondering how I would best determine what choices have been made, and if would be good to remove all objects from
    a collection that has NOT been chosen?
    Currently, it looks like this (exemple for one collection, but same solution is used for all collections)
    private Collection<Texture> textureList = new ArrayList<Texture>();
    private ArrayList<Texture> textureResult = new ArrayList<Texture>();
              for (Texture t : textureList) {
                   if (t.isSelected()) {
                        textureResult.add(t);
              }After this iteration, textureResult is used to create the PDF.
    This PDF contains lists with dynamic frames, so I need to now how many
    items was selected before creating the PDF.
    Wondering if this is the best/most efficient way to do this though?
    Maybe it doesn´t matter all that much with lists this small, but I´m still curios :-)
    I guess you could do something like this aswell
              while (textureList.iterator().hasNext()) {
                   Texture t = (Texture) textureList.iterator().next();
                   if (!t.isSelected()) {
                        textureList.iterator().remove();
              }Any suggetions?

    Dallastower wrote:
    I´m wondering how I would best determine what choices have been made,Are you asking how to determine which boxes have been checked? Or do you know how to do that and you're asking how to associate those boxes with items in your Collections? Or do you know how to do that and you're asking how to keep track of those selected items in the Collection?
    I don't do GUIs, so I can't help with the first two, but for the third, you could create a new collection holding just the selected ones, or remove the unselected ones from the original Collection.
    and if would be good to remove all objects from
    a collection that has NOT been chosen?That's entirely up to you. If you create the original Collection when the user makes his selection, and only need it to survive one round of selection, that may be fine. But if you need to get back to the original collection later, and it's expensive to create, then you might want to just create a second collection and add items from the original to it if they're selected.

  • How do I find music that has been uploaded to iTunes from a purchased CD and iTunes is "unable to find the original file?" I no longer have the CD. I have tried all the usual methods of looking in my iTunes library and through Find. No Luck.

    How do I find music that has been uploaded to iTunes from a purchased CD and iTunes is “unable to find the original file?” I no longer have the CD. I have tried all the usual methods of looking in my iTunes library and through Find. No Luck.

    Backup drive?
    Subscribe to iTunes Match?
    If neither of the above and you don't have the CD and can't find your tracks on the computer then they you're stuck.  A file recovery utility will cost $100, plus another $100 for an external drive to which to resue the files, and may not even work.  You can buy a lot of CDs for $200.

  • How to find how many times a t code has been processed by a user

    How to find how many times a t code has been processed by a user I am not able to get the exact number from the ST03 or STAD/STAT transaction. I am requiring the specific number that this T code has been processed completely this many no of times for a specific period.

    You must be more precise with your question.
    How long is the time period which you want to check, few hours or several days or longer? And how many executions do you expect, 100, 10000 or millions?
    The STAD should help you, for the smaller numbers. There is no solution for the larger ones. Don't mix STAD and ST03, ST03 is aggregated STAD information
    and know only how often a transaction was executed in total.
    ST05 is no solution for your problem to much overhead, and yoou should trace only a short period.
    There is no tool to check usage of transactions in more detail because of privacy reasons.
    Siegfried

  • PO List in which Payment Terms has been changed

    Hi,
    Please let me know how can i find the PO List, in which Payment Terms has been changed.
    Is there any table for it..
    Plz help...

    Hi,
    The change documents are stored in CDHDR (Header table) and CDPOS (Item) tables.
    You can find out the list of PO objects in theses tables.
    Cheers,
    Satish

  • Auto TECO Orders for which finished date has been reached-Periodic Job

    Dear PP GURUS N EXPERTS,
    My company want to TECO all the production order automatically for which finished date has been reached or (Finish date is before current date).
    On SDN, I have found that it can be carried our by scheduling the variant of PPIO_ENTRY or COHV. and it will be a periodic job.
    I want to know that for this which parameters I have to select and where / how I mention that order finish date has been reached. Since it will be a periodic job.
    Early response will be highly appreciated.
    With thanks,
    DSC

    Dear DSC
    You can use tranaction code CO44, define a variant for periodic job.
    Important selection parameters :
    Status selection profile : define which kind of production orders you want to set TECO indicator, for example with status CNF or DLV.
    Basic finish date : define basic finish date, for example if you want to TECO the production orders whose basic finish date is less than or equal current date, when you create the variant, selection variable can be D ( D: Dynamic date calculation ), name of variable can be "current date"
    Actions : please select the indicator "complete Technically".
    You can have a try, please let me know the result.
    Qiu

  • ERROR - Select a location to which a plant has been assigned

    1 Message
      Select a location to which a plant has been assigned  (Item  BOLT&NUT 4.6 COMM HEX HEAD BLK 10X170MM ) 
    this is the error message I get any idea how to fix it?
    Cheers
    B

    Hi. I presume the plants are linked correctly to the new company code in the backend, table T001K?
    Also, check the entries in SRM in table BBP_LOCMAP.
    Are the plants assigned to the right company codes in this table?
    There is an issue if you replicate plants to SRM then change the company code assignment SRM does not get updated.
    To correct BBP_LOCMAP you can use function BBP_CHANGE_ORGANIZATION.
    Regards,
    Dave.

Maybe you are looking for