title: Swing: how do I close a dialog when the ESC key is pressed?
body: <p>GUI development with Swing.</p>
  
  <p>I have a custom dialog for choosing a file to be opened in my application; its class extends <code>javax.swing.JDialog</code> and contains, among other components, a <code>JFileChooser</code>, which can be toggled to be shown or hidden.</p>
  
  <p>The <code>JFileChooser</code> component already handles the ESC key by itself: when the file chooser is shown (embedded in my dialog) and I press ESC, the file chooser hides itself.</p>
  
  <p>Now I would like my dialog to do the same: when I press ESC, I want the dialog to close. Mind you, when the embedded file chooser is shown, the ESC key should only hide it.</p>
  
  <p>Any ideas ?</p>