java - Creating a file from a jFileChooser component -
i using jfilechooser
part of export feature. user able either select file jfilechooser
's file viewer or enter name of file in filename text box. i've read it's possible value using getselectedfile()
method, have listeners call getselectedfile()
, attempt checks before executing export.
the problem i'm encountering getselectedfile()
method returning null when enter name filename text box manually. add more confusion, getselectedfile()
method work in 3 different situations:
- i populate via
setselectedfile()
(a user has clicked value table , usesetselectedfile()
) - i click existing file in file viewer
- i hit enter after populating filename text box
i have 3 file filters have had same behavior regardless of if enabled or not.
listeners call getselectedfile()
follows:
- event listener keyreleased
- event listener mousepressed.
- propertychangeevent listener on jfilechooser
- action listener on jfilechooser
is there better way listen jfilechooser user input? feel i'm missing obvious ... appreciated!
edit little more info ...
i have jfilechooser
component in jsplitpane
, in jframe
. i'm not calling showopendialog
input user. component accessible part of form.
what listen user input he/she types. have 'start export' button leave disabled until user has entered valid filename in filename textbox in jfilechooser
component. accomplish have keyevent listener use filename user types in.
further edit
here action listener code:
jfilechooserexport.addactionlistener(new java.awt.event.actionlistener() { public void actionperformed(java.awt.event.actionevent evt) { jfilechooserexportactionperformed(evt); } });
i have property change listener here:
jfilechooserexport.addpropertychangelistener(new java.beans.propertychangelistener() { public void propertychange(java.beans.propertychangeevent evt) { jfilechooserexportpropertychange(evt); } });
inside of both jfilechooserexportpropertychange , jfilechooserexportactionperformed trying file user has selected invoking getselectedfile(). in both cases, however, remains null until user 1 of 3 methods described above
read section swing tutorial on how use file choosers. demo code there works fine me.
Comments
Post a Comment