How to keep filename in textfield when filter is changed in a filechooser

Hi, guys,
I met a problem to keep filename in textfield when filter is changed in a filechooser
for example, a JFileChooser has two filters
*.jpg
*.png
Before I open JFileChooser, I used setSelectedFile(File) to set "aaa.jpg" as default name in textfield.
when I change the filter to "*.png, ", I want to change the text in textfield to "aaa.png", Actually, I used setSelectedFile(File), If there is an existed file named "aaa.png", this file will be selected on fileView, but the name will not be shown on the textfield. Anybody has ideas?
Thanks in advanced.

I really thank you for your answer, but it seems you misunderstand what I said because of my poor english..
what I said is:
after you open the filechooser, the filechooser has a combobox to choose file filter and a field to show filename.
what I want is:
when you open the filechooser, initial name in field is "test. jpg"
change filter, "test.jpg" will be change to "test.gif" in the field.
I don't want to close the filechooser.
That's why I used a listener to listen JFileChooser.FILE_FILTER_CHANGED_PROPERTY event.
and I modified your codes
import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.io.File;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.filechooser.FileFilter;
class Testing extends JFrame {
     String defaultFile = "";
     JFileChooser fc = new JFileChooser(".");
     ExtensionFileFilter eff;
     public Testing() {
          setLocation(200, 300);
          setDefaultCloseOperation(EXIT_ON_CLOSE);
          JButton btnShow = new JButton("Show Chooser");
          JPanel p = new JPanel(new GridLayout(1, 2));
          p.add(btnShow);
          getContentPane().add(p, BorderLayout.SOUTH);
          pack();
          fc.addPropertyChangeListener(new Listener(fc));
          fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
          fc.setAcceptAllFileFilterUsed(false);
          fc.setFileFilter(new ExtensionFileFilter(".gif"));
          fc.addChoosableFileFilter(new ExtensionFileFilter(".jpg"));
          defaultFile = defaultFile.equals("") ? "Test.jpg" : "Test.gif";
          fc.setSelectedFile(new java.io.File(defaultFile));
          btnShow.addActionListener(new ActionListener() {
               public void actionPerformed(ActionEvent ae) {
                    fc.showOpenDialog(Testing.this);
     public static void main(String[] args) {
          new Testing().setVisible(true);
class ExtensionFileFilter extends FileFilter {
     String fileTypes = "";
     java.util.List extensions = new java.util.ArrayList();
     public ExtensionFileFilter() {
     public ExtensionFileFilter(String ft) {
          fileTypes = ft;
     public String getDescription() {
          return fileTypes;
     public boolean accept(File f) {
          if(f.isDirectory()) return true;
          if (f.getName().endsWith(fileTypes)) {
               return true;
          return false;
class Listener implements PropertyChangeListener {
    JFileChooser fChooser = null;
    Listener(JFileChooser fChooser) {
        this.fChooser = fChooser;
    public void propertyChange(PropertyChangeEvent evt) {
        if (evt.getPropertyName().equals(JFileChooser.FILE_FILTER_CHANGED_PROPERTY)) {
             FileFilter fileFilter = (FileFilter) evt.getNewValue();
            if (fileFilter != null) {
                String fileName = null;
                if (fileFilter.getDescription().equals(".jpg")) {
                    fileName = "Test.jpg";
                } else if (fileFilter.getDescription().equals(".gif")){
                     fileName = "Test.gif";
                String newFileName = "C:\\" + fileName;
                fChooser.setSelectedFile(new File(newFileName));
}Thanks again.
Message was edited by:
JadeSword

Similar Messages

  • How to keep original aspect ratio when cropping in Camera Raw?

    How to keep original aspect ratio when cropping in Camera Raw? Cant figure it out! With shift, the aspect ratio is 1:1. But I didnt set it to 1:1 (I checked "normal").

    The Shift key works once you’ve set your crop ratio.  DSLRs would typically do 2:3 and others sometimes do 3:4.

  • How is the resolution variable or when would we change the resolution of an image and why?

    How is the resolution variable or when would we change the resolution of an image
    and why?

    It all depends on the output:
    * for viewing on screen 90 -120 ppi
    * for printing on a laser printer 180  -300 ppi
    * for printing on a desktop printer 240 - 300 ppi
    Some people claim 360 ppi is optimum but I don't see any difference compaired to 300 ppi at least not with the naked eye...

  • How to deal with the situation when the database change into ms-sqlserver ?

    Hi,dear all,
    How to deal with the situation when the database change into ms-sqlserver or other database?
    Now, i want to build a j2ee project with ORACLE ADF bc,but this project may be used in several diffrent databases for example oracle db,ms db,mysql and so on.however,if i have developer this project in jdeveloper and this project connection was config as a oracle database,and then,can this project be reused for other databases espasially including the model codes? if yes,how should i do?
    all who know how to resolve this,tell me pls,thanks.
    bruce Li,
    China
    Message was edited by:
    user526724

    Hi Paulbin,
    Do you want to supply a function-pointer to a DLL so it can call[back] your VI?  Here's how it can be done with .NET, though, that solution requires a C compiler.   A single "VI_to_function-reference" utility could handle all cases where the callback passes no parameters.  Maybe someday somebody will share that dll.
    Did you know that LabVIEW can use Events for some COM-signals change?  See pic.  (Note: DTR is not listed - - )
    Another question is another function's prototype is WORD SetTestType(WORD comHandle, bool type1, bool type2, bool type3),   I tried to use a boolean control and a Boolean to (0,1) node in labVIEW to pass parameters to CLF, I config the bool input value as U8(according to C++ bool type) and U32(according to WIN32 BOOL type), it dose not help, when I execute the VI, LabVIEW will be disappeare, it seems to be closed, I must start it again.
    Could someone has similar experience on this points?
    It's easy to crash LabVIEW misusing CLF - maybe there's another reason for the crash besides bool mis-match(?)  Do you know which "Calling convention" is required?  What type is comHandle? (where does comHandle come from?) 
    Cheers!
    Message Edited by tbd on 03-23-2007 09:34 PM
    Message Edited by tbd on 03-23-2007 09:35 PM
    "Inside every large program is a small program struggling to get out." (attributed to Tony Hoare)
    Attachments:
    evt.jpg ‏7 KB

  • How can I terminate my sequence when DI signal changed?

    Hello, I have a problem that  I want to stop my sequence by DI signal changed.
    How can I terminate my sequence when DI signal changed?
    Thanks
    Solved!
    Go to Solution.

    Hi, you can test the DI signal in vi using a while structure in another thread while main sequence is running. Then you can make use of an if statement to determine whether to get on running the sequence by the value of the vi.

  • How to keep old session id when a new session is created in web site

    Hi,
    I have a question about HttpSession in a Struts framework based project development.
    I have a web page "a.jsp" in public site (no need login) which can navigate to other pages/links. There is a button on "a.jsp" to popup a new window "pop.jsp" and create a session (session1). Usually, when I navigate to other pages/links from "a.jsp", it doesn't affect this "pop.jsp" and its session1. However, if I try to goto a secure site - a login page "login.jsp" from "a.jsp", since the "login.jsp" needs to kill current session before the login, the current session1 within the "pop.jsp" is killed at that time. When I go back to "pop.jsp", it will create a new session2 and the original session1 attributes does not exist any more. Therefore, I need to save the session1 id in somewhere to compare it with new session2 id when session is changed, and display some message in "pop.jsp".
    Do anyone know how/where to keep session1 id? Any sample/suggestion would be appreciated.
    Hanna

    check reply 2 of [http://forum.java.sun.com/thread.jspa?threadID=5279453&tstart=0|http://forum.java.sun.com/thread.jspa?threadID=5279453&tstart=0]
    like that you can comapre

  • How to keep LIN at hight when no data on it?

    Hi All,
    I have a question: how to keep LIN at hight level when no data on it?
    My card is PCI-8516
    Thanks a lot.

    I release LIN, so bus is low.

  • How to keep Ipod in iTunes when undocked

    I want to be able to see and manage my ipod music while it is undocked. I did this before, but for the life of me, can't figure out how to keep the iPod showing in iTunes when it's undocked. Any help would be appreciated. Thanks!
    Randy
    Dell   Windows XP  

    If it's not connected to the computer, you can't do anything with the iPod.
    You can Enable disk use in iTunes prefs -> iPod and it will not dismount.
    I want to be able to see and manage my ipod music while it is undocked.
    That is what iTunes is for.
    Make the changes in iTunes and then update the iPod.
    Any changes you make on the iPod will not be reflected in iTunes.
    When you have to Restore the iPod (you will), all changes will be lost.

  • How to keep original email open when replying?

    I bet this is somthing simple, but I just can't figure it out. When I click reply on an email, the original closes. It's no big deal, but I like to have the original open to refer back to. Is there a way to set my mail to keep the original open when replying. Thanks in advance
    MacBook   Mac OS X (10.4.7)   Got my new MacBook. It's a wonderful thing!!! Video iPod!! Lots of toys!!!

    You're welcome.
    I am not getting the other option about keeping
    the preview pane visible.
    It seems you're not aware that the part of the main window where messages are listed can be split in two parts: the messages list at the top and the preview pane at the bottom. You can do this by either (1) dragging upwards the thin horizontal separator bar that's at the bottom of the window, or (2) just double-clicking on that bar (it has a tiny hole in the middle).
    How come when I delete an email in my .mac account,
    I have to delete it twice from the trash?
    Well, the answer to that question is way more involved than you might think.
    The behavior you've observed happens in Mail to any IMAP-type account for which deleted messages are stored locally (i.e. Preferences > Accounts > Mailbox Behaviors > Store deleted messages on the server has been turned OFF). The "reason" is that storing deleted messages locally for IMAP-type accounts causes Mail to move deleted messages in that account to a Deleted Messages (AccountName).mbox folder located within ~/Library/Mail/Mailboxes/.
    Deleting a message already in a Trash mailbox should cause the message to be permanently erased, BUT deleting a message from a mailbox located within ~/Library/Mail/Mailboxes/ (i.e. an "On My Mac" mailbox) should cause the message to be moved to the "On My Mac" Trash. Thus, in the particular case of a Deleted Messages (a Trash) mailbox stored within ~/Library/Mail/Mailboxes/, there are two conflicting behaviors, and it seems that Mail takes the latter into consideration first, i.e. deleting a message from the account's Trash under those conditions causes it to be moved to the "On My Mac" Trash instead of being permanently erased as would happen if the Deleted Messages folder was located within the account folder.
    This could very well be an oversight (a bug) rather than intended behavior, but that's how it works in the current version of Mail. If you're curious, the following somewhat amusing (but also lengthy and confusing) threads would give you an idea of how long it took me to figure out this one:
    emails won't delete on first try
    IMAP messages need trash deleted twice

  • How to keep details grouped together when have more than 1 details section

    I want to create a report that has two different detail sections, and then have the report first print all of the results of the first detail section (DETAIL A), followed by the results of the second detail section (DETAIL B).
    But CR prints the first line of DETAIL A, followed by the first line of DETAIL B. It then goes on to the second line of DETAIL A, followed by the second line of DETAIL B, and so on.
    Can anyone tell me how to keep DETAIL A together, followed by DETAIL B?
    thx, jon

    Assuming the data for the two formats are not in the same record, add a new field to the data record (or calculate it based on the record's data) with a value of A or B, then group by it.
    If the data IS in the same record (i.e., one data record generating both formats), subreports are the only way that I can think of...
    HTH,
    Carl

  • How can I execute a vi when a switch changes

    I have a switch which controls the input to a VI (it is slightly more complicated than that, but that's the basic idea).
    The VI is a "set" function.  So it really should only execute when the value changes. 
    Is there some way to set the switch so that there is only data available on the output when the switch is switched, thus executing the VI once?
    If not, what is the best way to do this?
    Thank you.
    B.

    BPerlman wrote:
    Thank you.
    An event structure sounds like just what I need.  I am not going to get into the design patterns you mentioned here .... this is a demo program and there is a switch on the front panel that demos a feature in our library, turning it on and off.  I just want to call a library function to turn the feature on or off at user request....the rest of the demo works (right now, I call the VI to turn on/off the feature every time through my main loop -- this is ugly and causes us timing problems... but everything else is finished)
    I tried to add an event structure but don't seem to have it in my edition of LabVIEW....
    What I just added now is a shift register to save the value of the switch between loop iterations, and I compare it to the current value, then feed it into a true/false case structure, only calling my "set" VI when the two values are different...
    Is there a better way, or is that all I can do unless my company buys a fancier LabVIEW version?
    Thanks.
    B.
    Shameless plug for an idea in the idea exchange. Since this would have helped you resolve your issue you might want to consider giving a kudo to this idea.
    The way you are doing it now with the shift register is pretty much the only way you can do this without using an event structure.
    Mark Yedinak
    "Does anyone know where the love of God goes when the waves turn the minutes to hours?"
    Wreck of the Edmund Fitzgerald - Gordon Lightfoot

  • How to keep files from disappearing when using Dynamic link to AE in PremProCS4?

    I am at my wits end here and hope someone can offer a solution.  I use Dynamic Link in PremProCS4 to link a clip in my timeline to AfterEffects.  I follow the instructions in my book and everytime I close my files and reopen..I loose the clip along with the effects...I get the place card instead.  Here are the steps I do as per the Adobe Classroom in a Book Explains:
    I double click on my .MTS file in the Project Board so it comes up on my Source Screen.
    I take select the part of the clip I wish to use in my timeline and drag it to the appropriate spot on a video layer.
    I then right click the "clip" and select "Replace With After Effects Comp"
    I then name the new file.  name or whatever.aep
    It opens in AE
    I then apply two simple effects... keying and a cartooning effect I use from NewBlue Cartooner.
    As instructed I then go directly back to PremPro and do a "render" by pressing the Enter Key.  This does not work since I only get a yellow bar above the clip instead of a red on???
    So then I save the PremPro project and close it then go to the AE project, save and close it.
    When I reopen PremPro the file has a place card in it and in AE it says I am missing a file.
    I have tried many different ways to do this process including re-importing the .MTS file.
    I can close PremPro and reopen it and all is the same as long as I don't close the AfterEffects project.  Once AE is closed it looses the file.  On a note here I keep all my computer source files in the same place and it never changes plus they are in my PPro Project as well.  I never change the names so this isn't this reason.
    Is there a tried and true method to select a piece of clip in the video layer in Prem Pro and add effects from AE and not have it misplace the files?
    Thanks  Kate

    Hi Curt, and thank you for taking the time to respond.
    Its odd how I've been trying to figure this one out for a long time and I tried your suggestion but it didn't make any difference..darn.
    In the AE forum they say this is quite common and no one really knows why...double darn.
    So I went back with a fresh mind this morning and tried something else..and it worked...so far anyway.
    So far I figured it out... I guess I just needed to ask the question and write it all out to help get my brain working in the right direction: 
    Since the normal process to do this doesn't work for me ..and apparently many others..here is the solution for those of you having similar issues.
    In PremPro select the desired clip you wish to place effects on
    Rename it and save
    R click and "Replace with AE composition"
    Name new file
    You will see three files pop up in AE in the project panel.
    The original source clip .. in my case.. shows an icon that lets me know it isn't the true file.
    Highlight this file with a click and then go Ctrl H (for PCs)
    The group of computer source clips you use for your project will come up.. double click on the original clip you had imported into your PPro project.
    The source file icon in AE will change to an icon that denotes the true file...save
    Go to your still open Ppro project and make sure it carried the effects over..save.
    Now you can save and close the AE project.
    So for this works for me today and I hope this helps anyone else dealing with a similar issue.
    Thanks.

  • How to keep image from moving when cropping?

    I have been using LR for quite a while, but all of a sudden when I crop a photo, the image slides to the left or right and out of view.
    In the past when I move the crop frame the photo would not move, that way I can see exactly how much of the photo I am cropping.
    I have tried doing searches regarding a setting, but all I get are answers about locking the crop ratio and that is not what I need.
    I need to keep the entire image in view when I slide the crop window.
    Thanks!

    Geoff the kiwi wrote:
    Agfaclack - no need to even mention PS for this, it is only confusing.
    i don´t think so.
    because i had the same "problem" when i started with LR.
    i was confused because lightrooms crop tool worked different then photoshops and i thought i had changed some settings that made LR behave "strange".

  • How to keep scale for height when resizing width?

    Hi i have a serious of images different sizes/ ratios, which need to display at a fixed width of 50. Great works... but how do I resize the height to keep it at its original ratio?
    this.attachMovie(small_image, "number1_mcs" + loop , this.getNextHighestDepth(), {_x:50 + (loop*50),_y:300,_width:50,_yscale:?????????????});}
    many thanks in advance
    Dee

    Thanks for your help, being new, "terms", practices etc which others may fully understand, can fly right over ones head... It doesn't mean its impossible to understand them just grasping the exact meaning and then the specifics of any technicality can cause one to pull out more hair, especially when tired...
    I fixed the problem using the following... i hope its not too ugly..!
    Dee
    this.attachMovie(small_image, "number1_mcs" + loop_n1 , this.getNextHighestDepth(), {_x:75 + (loop_n1*40),_y:350});
    var aspect_ratio_x = this["number1_mcs"+loop_n1]._width;
    var aspect_ratio_y = this["number1_mcs"+loop_n1]._height;
    var aspect_ratio = (aspect_ratio_x / aspect_ratio_y);
    this["number1_mcs"+loop_n1]._width = 40;
    this["number1_mcs"+loop_n1]._height = this["number1_mcs"+loop_n1]._width / aspect_ratio;

  • How to keep files from disappearing when using Dynamic link to AE from PremProCS4?

    I am at my wits end here and hope someone can offer a solution.  I use Dynamic Link in PremProCS4 to link a clip in my timeline to AfterEffects.  I follow the instructions in my book and everytime I close my files and reopen..I loose the clip along with the effects...I get the place card instead.  Here are the steps I do as per the Adobe Classroom in a Book Explains:
    I double click on my .MTS file in the Project Board so it comes up on my Source Screen.
    I take select the part of the clip I wish to use in my timeline and drag it to the appropriate spot on a video layer.
    I then right click the "clip" and select "Replace With After Effects Comp"
    I then name the new file.  name or whatever.aep
    It opens in AE
    I then apply two simple effects... keying and a cartooning effect I use from NewBlue Cartooner.
    As instructed I then go directly back to PremPro and do a "render" by pressing the Enter Key.  This does not work since I only get a yellow bar above the clip instead of a red on???
    So then I save the PremPro project and close it then go to the AE project, save and close it.
    When I reopen PremPro the file has a place card in it and in AE it says I am missing a file.
    I have tried many different ways to do this process including re-importing the .MTS file.
    I can close PremPro and reopen it and all is the same as long as I don't close the AfterEffects project.  Once AE is closed it looses the file.  On a note here I keep all my computer source files in the same place and it never changes plus they are in my PPro Project as well.  I never change the names so this isn't this reason.
    Is there a tried and true method to select a piece of clip in the video layer in Prem Pro and add effects from AE and not have it misplace the files?
    Thanks  Kate

    Hi Mylenium, and thank you for taking the time to respond.
    Your idea of renaming comps got me to thinking..hmm.
    So I went back with a fresh mind this morning and tried something else..and it worked...so far anyway.
    So far I figured it out... 
    Since the normal process to do this doesn't work for me ..and apparently many others..here is the solution for those of you having similar issues.
    In PremPro select the desired clip you wish to place effects on
    Rename it and save
    R click and "Replace with AE composition"
    Name new file
    You will see three files pop up in AE in the project panel.
    The original source clip .. in my case.. shows an icon that lets me know it isn't the true file.
    Highlight this file with a click and then go Ctrl H (for PCs)
    The group of computer source clips you use for your project will come up.. double click on the original clip you had imported into your PPro project.
    The source file icon in AE will change to an icon that denotes the true file...save
    Go to your still open Ppro project and make sure it carried the effects over..save.
    Now you can save and close the AE project.
    So for this works for me today and I hope this helps anyone else dealing with a similar issue.
    Thanks.

Maybe you are looking for