# openFile and JFileChooser change directory on backspace

**URL:** <https://forum.inductiveautomation.com/t/openfile-and-jfilechooser-change-directory-on-backspace/12025>\
**Category:** General Discussion\
**Created:** [August 10, 2016, 10:58pm UTC](https://forum.inductiveautomation.com/t/openfile-and-jfilechooser-change-directory-on-backspace/12025 "2016-08-10T22:58:25Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![steven.elam](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/steven.elam/32/4797_2.png) [@steven.elam](https://forum.inductiveautomation.com/u/steven.elam)\
**Post date:** [August 10, 2016, 10:58pm UTC](https://forum.inductiveautomation.com/t/openfile-and-jfilechooser-change-directory-on-backspace/12025/1 "2016-08-10T22:58:25Z")

</div>

When I use system.file.openFile() to select a file and I type a in the File Name text field, the file chooser changes directory up one level. This makes it very difficult to use. (I assume openFile() is using a JFileChooser because I get the same behavior if I import javax.swing.JFileChooser and call its showDialog() method.)

Is this a bug in the underlying Jython implementation? Is there a workaround?

Ignition platform: 7.5.10 (b1470)

---

<div class="post-metadata">

**Author:** ![jpark](https://avatars.discourse-cdn.com/v4/letter/j/a88e57/32.png) [@jpark](https://forum.inductiveautomation.com/u/jpark)\
**Post date:** [August 10, 2016, 11:04pm UTC](https://forum.inductiveautomation.com/t/openfile-and-jfilechooser-change-directory-on-backspace/12025/2 "2016-08-10T23:04:45Z")

</div>

It has been fixed in a later version.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [August 10, 2016, 11:14pm UTC](https://forum.inductiveautomation.com/t/openfile-and-jfilechooser-change-directory-on-backspace/12025/3 "2016-08-10T23:14:59Z")

</div>

Looks like 7.7.5 and later.

---

<div class="post-metadata">

**Author:** ![steven.elam](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/steven.elam/32/4797_2.png) [@steven.elam](https://forum.inductiveautomation.com/u/steven.elam)\
**Post date:** [August 11, 2016, 3:22am UTC](https://forum.inductiveautomation.com/t/openfile-and-jfilechooser-change-directory-on-backspace/12025/4 "2016-08-11T03:22:02Z")

</div>

We’re not able to upgrade at this point. Is there a workaround, such as programmatically disabling the keyboard shortcut for the “Go Up” action?

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [August 11, 2016, 1:30pm UTC](https://forum.inductiveautomation.com/t/openfile-and-jfilechooser-change-directory-on-backspace/12025/5 "2016-08-11T13:30:11Z")

</div>

If you create your own JFileChooser rather than using the scripting call, you can try something like this: [stackoverflow.com/questions/2064 … ne-level-b](http://stackoverflow.com/questions/20649909/backspace-while-entering-filename-in-jfilechooser-makes-directory-go-one-level-b)

---

<div class="post-metadata">

**Author:** ![steven.elam](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/steven.elam/32/4797_2.png) [@steven.elam](https://forum.inductiveautomation.com/u/steven.elam)\
**Post date:** [August 11, 2016, 10:22pm UTC](https://forum.inductiveautomation.com/t/openfile-and-jfilechooser-change-directory-on-backspace/12025/6 "2016-08-11T22:22:23Z")

</div>

I have a workaround that’s quite a bit simpler than the one you referenced, although I’m not sure I understand why it works. I derive from JFileChooser and redefine processKeyBinding() as a do-nothing method. To illustrate, execute the following code in the script playground in version 7.5.10 (if you have it available):

# This suffers from the “Backspace invokes ‘Go Up’ action” issue:

from javax.swing import JFileChooser  
chooser = JFileChooser(None)

if chooser.showOpenDialog(None) == FileChooser.APPROVE\_OPTION:  
print chooser.getSelectedFile()

# Whereas this does not:

from javax.swing import JFileChooser

class FileChooser(JFileChooser):  
def processKeyBinding(self, keyStroke, keyEvent, condition, pressed):  
pass

chooser = FileChooser(None)

if chooser.showOpenDialog(None) == FileChooser.APPROVE\_OPTION:  
print chooser.getSelectedFile()

I assume that the JFileChooser bug is in the processKeyBinding method and by essentially removing it I avoid the problem at the cost of losing whatever other keyboard shortcuts it implements. Character events are still handled correctly by the JTextField containing the selected file, so I’m content with the trade-off.

If someone has more insight into this or has a better solution, I’d like to hear it, but this workaround will do for now.
