JFileChooser as save dialog clears text field on change directory

I am trying to implement a basic save dialog using JFileChooser, which initiates with an initial file name, "untitled.txt". However, as soon as the directory is changed by the user, the text field is cleared. I want to ensure that whatever is in the text field when the user changes directories (i.e., untitled.txt may have been changed to something else by the user) stays visible throughout any kind of user navigation. I've tried all sorts of things, but nothing seems to work.
Thanks for your help.

Yes, it very well could be an OS/JDK issue. I'm using jdk 1.5 on Mac OS X (Tiger). Apparently, FileNameExtensionFilter is a jdk 1.6 implementation, because it doesn't work for me.
Here's my code:
JFileChooser fc = new JFileChooser();
String output = outputTextArea.getText();
        String selectedFile = "untitled.txt";
        File file = new File(selectedFile);
        fc.setDialogTitle("Save");
        fc.setMultiSelectionEnabled(false);
        fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        fc.setSelectedFile(file);
        setFileName(file.getName());
        int result = fc.showSaveDialog(this);
        if (result == JFileChooser.CANCEL_OPTION) {
            return;
        } else if (result == JFileChooser.APPROVE_OPTION) {
            file = fc.getSelectedFile();
            if (file.exists()) {
                int response = JOptionPane.showConfirmDialog(null,
                        "Overwrite existing file?","Confirm Overwrite",
                        JOptionPane.OK_CANCEL_OPTION,
                        JOptionPane.QUESTION_MESSAGE);
                if (response == JOptionPane.CANCEL_OPTION) return;
            if (!writeFile(file, output)) {
                setErrorMessage(ERROR5_1); //Just a custom error message and display.
                showErrorMessage();
                return;
        }Is there a workaround if this is an OS or JDK issue?
Thanks again for your help.

Similar Messages

  • What is the Table name & Field Name for Clearing text field in F-53 Transac

    Hi,
    I need prepare a functional specification for Clearing text field in Check Register.I am not able to find the Table name and Field Name for Clearing text field in F 53 transaction code.Kindly provide me the Table and filed name.so that i can proceed.Kindly help me.
    I will assign points.
    Thanks
    Sunitha

    Hi
    From the payment document you have to link to the clearing document (Number BSEG-AUGBL, same Fiscal year and Company Code) in the clearing document the text entered in the transaction can be found on item text (BSEG-TEXT).
    RF05A is a Structure name
    Ranga
    Edited by: Ranga Swamy on Dec 4, 2008 7:55 PM

  • Unable to clear text Field in Multi Screen JFrame GUI Application

    i am working with a Swing GUI project where I want to accept user input in a
    text field
    I have used singleton pattern which will create only one instance of object
    due to this when i move from one scree to another the input of textfield
    doesnt updated I have used setText method to clear the JTextField but it wont
    works
    Program one -- 1st screen
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.SwingUtilities;
    import java.awt.event.*;
    import javax.swing.JTextField;
    public class Frame1 extends JFrame
    public static Frame1 frame1;
    public JButton button;
    public JTextField input;
    public static Frame1 getInstance()
    if(frame1==null)
    frame1 = new Frame1();
    return frame1;
    public JButton getJButton(String mytext)
    JButton button = new JButton();
    button.setText(mytext);
    button.setBounds(450,450,150,50);
    return button;
    public void myGUI()
    JPanel panel = new JPanel();
    panel.setLayout(null);
    button = getJButton("1st Frame");
    addActionListener(button);
    input = new JTextField(10);
    input.setBounds(200,300,100,30);
    panel.add(input);
    panel.add(button);
    add(panel);
    setUndecorated(true);
    setSize(1024, 768);
    setVisible(true);
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    public void addActionListener(Object obj)
    try{
    JButton button1 = (JButton)obj;
    button.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent ae)
    String text = "";
    input.insert("", 0);
    Frame2.getInstance().myGUI();
    Frame2.getInstance().repaint();
    dispose();
    catch(Exception e1)
    System.out.println("Exception==> "+e1.toString());
    public static void main(String[] args)
    Frame1.getInstance().myGUI();
    Frame1.getInstance().repaint();
    program 2 - 2nd screen
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.SwingUtilities;
    import java.awt.event.*;
    import javax.swing.JTextField;
    public class Frame2 extends JFrame
    static Frame2 frame2;
    public JButton BackButton;
    public JTextField input;
    public static Frame2 getInstance()
    if(frame2==null)
    frame2 = new Frame2();
    return frame2;
    public JButton getJButton(String mytext)
    JButton button = new JButton();
    button.setText(mytext);
    button.setBounds(450,450,150,50);
    return button;
    public void addActionListener(Object obj)
    try{
    JButton BackButton1 = (JButton)obj;
    BackButton.addActionListener(new ActionListener()
    public void actionPerformed(ActionEvent ae)
    input.setText("");
    Frame1.getInstance().myGUI();
    Frame1.getInstance().repaint();
    dispose();
    catch(Exception e2)
    System.out.println("Exception==> "+e2.toString());
    public void myGUI()
    JPanel panel2 = new JPanel();
    panel2.setLayout(null);
    BackButton = getJButton("2nd Screen");
    addActionListener(BackButton);
    input = new JTextField(10);
    input.setBounds(200,300,100,30);
    panel2.add(input);
    panel2.add(BackButton);
    add(panel2);
    setUndecorated(true);
    setSize(1024, 768);
    setVisible(true);
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    In this application the status of TextField input remain same means it shows
    the earlier input in the textfield wnen I come to earlier or next screen.
    what is the solution to clear the TextField input while moving from 1st
    scrren to 2nd screen.

    multiple screens = multiple posts
    well done indeed - just another farking cross-poster
    [http://www.coderanch.com/t/492998/Swing-AWT-SWT-JFace/java/unable-clear-text-box-Multi#2218566]

  • Clearing text field

    Hi,
    I have a page where you scan a barcode into a text field submits when enter pressed. If the barcode exists a report appears showing that record. The barcode must stay in the text field.
    My question is if I scan a barcode and the barcode does not exist and then I scan another barcode, the previous barcode stays and gets appended onto the new barcode. How do I clear the barcode data out of the text field when I scan in a new barcode?

    Hi,
    Add something like the following into the report region's Region Footer setting:
    <script type="text/javascript">
    if (#ROWS_FETCHED# == 0)
    $x("P36_BARCODE").value = "";
    </script>Replacing P36_BARCODE with the actual name of the barcode field.
    #ROWS_FETCHED# is populated with the number of rows fetched on the page for the report. If this is 0 (zero), then the script will run, and the field will be cleared.
    Andy

  • Clearing text field after query

    I have seen alot of old post on this but no answers, I am wondering if anyone knows how to accomplish clearing a text field after a query has been executed?
    Example:
    User types a query in the search field, clicks submit then the query is returned and the search field is empty again ready for the next query.

    I tried that and I was getting "(null)" in the value of the column I queried.
    This is what I came up with and it seems to be working. In the Page Definition click Edit Attributes and add this line to the On Load section:
    onload="html_GetElement('PX_SEARCH').value=''; html_GetElement('PX_SEARCH').focus()"That will clear the field and focus the cursor in the same field so its ready for another query.

  • PDF form text fields' options change when opened in READER on a MAC.

    I created a PDF form using Adobe X PRO. All fields are UNCHECKED for Property/Options/ "scroll long text". I save and distribute the form as a "reader extended pdf/enable additional features" so it can be saved and returned using READER.
    When a Mac user opens the extended form in Adobe READER, ALL the text fields change to scroll. When he returns the completed form to me, every text field, even signature and date fields, are changed to scroll text.
    What is happening in the transition from PC to MAC?

    Preview is the default PDF viewer on the Mac. It should never be used with PDF forms. Just let them know that they should use Adobe Reader. Provide a link or URL where it can be downloaded and let them know that it's free.
    There are things you can do so that it doesn't work in Preview, but it involves some scripting. If interested in this approach, post again.

  • Value of input text field not changed!

    hi,
    i have a select menu. when i change the value of the select menu, i have the event method and in the event method i change an value of a other input text field, but in the html page, the input text doesn't change his value.
    i bind the input text field to the value field in class with the folowing command.
    <h:inputText binding="#{backing_main_test:testInputField}" value="#{backing_main_test.testValue}"/>
    please help me.
    thanks, christoph

    <h:inputText binding="#{backing_main_test: <--- was that colon intentional?

  • How to clear text fields when the user navigates back to the screen

    Hi,
    Does anyone have any idea on how to clear the text input fields and dropdown boxes when the user navigates back to the screen, say for e.g. create screen?
    My issue is that i have plenty of fields in the create screen within a form. Is there a way to avoid programaticaly blanking out every field and just do it at the form level using an api to reset to a state before the user entry?
    Thanks

    This code allows you to make it more generic, and you would need to tweak it if there are more than TextInput controls, but it should provide some ideas.
    As far as using states, you could use SetProperty to set the text to empty, but that might be messier.
    <?xml version="1.0"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
      <mx:Script>
        <![CDATA[
          import mx.containers.FormItem;
          import mx.controls.TextInput;
          import mx.events.IndexChangedEvent;
          import mx.core.Container;
          private function clearSreen(evt:IndexChangedEvent):void{
            var view:Container = tn.selectedChild as Container;
            for each(var child:Object in view.getChildren()){
              if(child is FormItem){
                var subchild:DisplayObject = child.getChildAt(0);
                if(subchild is TextInput){
                  TextInput(subchild).text = "";
        ]]>
      </mx:Script>
      <mx:TabNavigator id="tn" resizeToContent="true"
        change="clearSreen(event)">
        <mx:Form id="frm1" label="View Number One">
          <mx:FormItem label="First name:">
            <mx:TextInput/>
          </mx:FormItem>
          <mx:FormItem label="Last name:">
            <mx:TextInput/>
          </mx:FormItem>
        </mx:Form>
        <mx:Form id="frm2" label="View Number Two">
          <mx:FormItem label="Address1:">
            <mx:TextInput/>
          </mx:FormItem>
          <mx:FormItem label="Address2:">
            <mx:TextInput/>
          </mx:FormItem>
          <mx:FormItem label="City:">
            <mx:TextInput/>
          </mx:FormItem>
          <mx:FormItem label="State:">
            <mx:TextInput/>
          </mx:FormItem>
          <mx:FormItem label="Zip code:">
            <mx:TextInput/>
          </mx:FormItem>
        </mx:Form>
      </mx:TabNavigator>
    </mx:Application>
    If this post answers your question or helps, please mark it as such. Thanks!
    http://www.stardustsystems.com
    Adobe Flex Development and Support Services

  • Clear text field cache?

    I have a dynamic form that contains confidential financial data fields. How do I configure the form to not present a list of cached values from previous entries that match the string that is entered to that point? I'd really hate for client B to see client A's financial data.
    Thanks!

    I used the code (event.target.nocache = true; as described) in Designer 7.0.04 and it works fine. I suspect in your case that there is JavaScript code before that line that is producing an error (e.g., syntax) causing further JavaScript processing to abort. I have found that to be problematic during development and debugging. OH! If only JavaScript had a better development environment.
    NOTE: "this.nocache=true;" was not found to work -- at all in any event I tried.
    Though I am sure you have an answer by this date, this is for future developers.

  • TEXT FIELD NOT CHANGED IN JVA DOCUMENT

    Hi Experts,
    Have an issue here. When we change a document line item text in a FI document in FB02, the same change is not reflected in the JV document in GJLI. Can you please explain why this happens or if there is a solution for this.
    Thanks,
    Hari Dharen

    Hi,
    1.  First Check if Text is updated in Material document or not. if not then
    Check in system if function module MBCF0002  is activated or not.
    if it is activated then code must be written there for Text to flow.
    follow SAP Notes 1518592 - Table MSEG-SGTXT is not filled
    MBCF0002 exit EXIT_SAPMM07M_001 include ZXMBCU02
    2. please check notes 837859 for MIRO Text because there are three differnet Text in MIRO
    Hope Help U !
    Regards,
    Pardeep Malik

  • CS6 static text field fonts change size on export to iOS

    I've resolved my previous isue with opening my CS5.5 project in CS6 ... but now when I package the project for iOS, all of my text is slightly larger nad offset compared to what Isee in Flash Pro CS6.  I'm using Classic Text - Static Bitmap (no anti aliasing).
    Are their new features with regard to Fonts that I should be aware of?
    Any ideas?

    WARNING:  What you'll see here is undocumented, unsupported, could break at any time, should not be used to control critical functions like landing airplanes, yada, yada, etc., etc.  Use at your own risk -- it's up to you to make it work.  I have no recollection of ever typing this, so can't be held accountable.
    Phew!  Anyway, a couple of months ago, I asked Jeffrey Friedl the same question.  His reply:
    I asked for (and was given) permission to tell you:
         f:static_text {
             title = 'Visit Site',
             mouse_down = function()
                LrHttp.openUrlInBrowser( someUrl )
             end,
             [ WIN_ENV and 'adjustCursor' or 'adjust_cursor' ] = function()
                logger:debug('mouse_over handler activated')
             end,
             text_color = LrColor( 0, 0, 1 ),
    Enjoy!
    When asked if I could share the information, he replied:
    The permission didn't come with any restrictions, so I guess it's okay to
    spread around.
    Anyway, the critical part of the code snippet that's missing is what to do in the "mouse_over handler" function.  What I did for all of my links was to call a common function that would launch an async task that would change the color of the link, then change it back after a period of time.
    I passed "self" (the static_text being hovered over) to my common routine so it could keep track of the active link, and reset the previous link when the user hovers somewhere new.
    Good luck, and, as Jeffrey said, Enjoy!
    -Don

  • Changes from Visio 2010 to 2013 - highlighting entire line drawing document with text fields and changing line colors

    I work with very large visio drawings that are basically line drawings (network drawings) with text boxes indicating equipment location. We work in future and current drawings, future has colored lines indicating connection type and objects have text in
    them that indicate if they are new by having red text. Current drawings have all black lines and black text.
    Here's my dilemma, previously I would Ctrl+A and then change all text and all lines to black in Visio 2010, everything would change no problem. In Visio 2013 every text box now get's a black border around it, I've tried selecting all text boxes at once
    and trying to remove the line but no luck.
    These drawings are HUGE and it takes me a good hour just to change between future and current where previously it took me seconds. I have many coworkers and we're all experiencing he same issue with the move to 2013.
    Is there a macro or some vb script I can utilize to select all text boxes and remove the black outline?
    Hope you can help!

    try this macro
    Sub Simple()
    Dim sh As Shape, counter As Integer
    ActiveWindow.SelectAll
    For counter = 1 To ActiveWindow.Selection.Count
    Set sh = ActiveWindow.Selection(counter)
    If Len(sh.Text) > 0 Then sh.Cells("Geometry1.Noline").FormulaU = "IF(LEN(SHAPETEXT(TheText))>0,1,0)"
    Next
    MsgBox "All text borders set invisible"
    End Sub
    if in your drawings you have only lines and text label (NOT rectangles, circles and other shapesconteined text for example) this macro can help !

  • Text field values changing to "true" when I click submit by e-mail button

    I have some logic in my e-mail submit button to determine who needs to receive the form based on information in the form.  Based on my sample code, when I click the submit by e-mail button and TextFiel4.rawValue is D781008CX03, it will actually change the value in TextField4 to "true" when submitting the form.  What can i do to fix this issue?
    if 
    (TextField4.rawValue = "D781008CX03" && CheckBox10.rawValue == true){ 
    var myDoc = event.target;myDoc.mailDoc(
    false, [email protected]
    , "", "", "Request to Add "
    +FuelRating.rawValue , "You have a new industrial request to add "
    +FuelRating.rawValue);}

    Ahhh!!
    Amature mistake  .  Thank you for the help and the quick response!!

  • Clear the content of a text field

    hello guys,
    i have text fields in a screen which are been populated in the PBO. Now i want to clear the content of the  text field such that the user can input new values in those text field.
    so, anyone knows how i can achieve this.
    tried,
    text field name = ' ', space.
    clear text field name.
    but none worked.
    thanks you for ur help.

    Hi,
    I think you have doen some thing like this in PBO.
    screen_field_name = 'some value'.
    So now in PAI you can do the following.
    CASE sy-ucomm.
         WHEN 'F_CLEAR'.    " Fcode for the clear button in the screen.
          CLEAR : field_name.
      ENDCASE.
    If the field is a mandatory field then you need to create a AT EXIT module and write the same code in that.
    Hope it helps you.
    Thanks,
    Sri.

  • JFileChooser SaveDialog clears filename when you change extension

    I created an instance of my GraphicFileChooser class which extends JFileChooser and named the instance chooser. I execute chooser.showSaveDialog(null); This brings up JFileChooser's save dialog. Everything works fine for the most part. I am able to save and cancel and change files and overwrite and everything. The one problem I have is that when I change the file extension type in the dropdown(i. jpg to png) the text box for the file name clears itself. I want the text box to always show what is typed in it and never clear. I have spent way to much time trying to work this minor detail out and would greatly appreciate it if somebody could help me. Thank you

    Look these issues up in the Bug Database.
    If you don't see them, have the Windows 2000 user post
    a bug report explaining in detail the issue, so that
    those wonderful people who work on such issues can
    have the info available to resolve them.When I say post a bug report, I mean post the bug report **in the Bug Database**. Don't post them in the forums.

Maybe you are looking for

  • MT940 statement BACS DME auto clearing

    Hi Friends, Needed some help on automatic clearing of bank open items when processing electronic bank statement (MT940 format). When automatic payment is done through F110 , a DME file is created. In the bank statement config , the external transacti

  • Can you make Wiki Templates in Lion ?

    Can you nake Wiki Template with Lion server ?  Or do I have to start every page from scratch.

  • Multiple Database Connections in ADF?

    Hi, For school we have a project. The goal of this project is to create an application that can generate business rules in PL/SQL. The application must be build using JDeveloper 11g 11.1.1.3.0 with ADF and must be a swing application. We didn't have

  • Creating a windows simulator

    Hello, I am interested in creating a windows simulated envirnment, ie, a user could perform a certain windows task just as if he or she were actually in windows. This would be limited to just the task at hand. Lets say I wanted to simulate using star

  • Sun ONE Web Server 6.1SP2 B04/07/2004  core dump enablement

    What is the procedure to enable core dump for future analysis? Earlier versions code changes for magnus.conf does not seem to work!