Closing JInternalFrame with ESC-Key?

Hi all.
Is there a way to close JInternalFrames with the ESC-Key?
For JDialogs that works good (adding an action to the rootPane's ActionMap) but I cannot figure out how to add this functionality for JInternalFrames as well.
Any hints?
Regards
Carsten

try this
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class TextButton extends JFrame
JFormattedTextField tf1;
Container con;
public TextButton()
con=getContentPane();
con.setLayout(new FlowLayout());
tf1=new JFormattedTextField();
tf1.setValue(" ");
tf1.addKeyListener(new KeyAdapter()
     public void keyPressed(KeyEvent ke)
     if(ke.getKeyCode()==10)     
System.exit(0);
con.add(tf1);
setSize(400,400);
setVisible(true);
public static void main(String args[])
new TextButton();
}

Similar Messages

  • CS4 64bit Bridge slideshow will not end with ESC key

    I have just installed CS4 64bit on a new computer with Windows 7 64bit. I've done the update so now Bridge sees the CR2 files from my Canon 5D MkII but when I go into slideshow...which I use extensively for quickly reviewing images, I cannnot end the slideshow with the normal ESC key stroke... Which really kills the utility of slideshow. Any suggestions as to getting this to work or other ways to close slideshow? Now the only option is to croll through all the images in the folder at which point slideshow will close.

    I can't help that Adobe gave me a download of 64bit CS4...but that is what they did...so obviously they have a 64bit version of CS4.
    Sorry, as a Mac user PSCS 5 was the first version in 64 bit, PSCS4 was only 64 bit for Windows, However, like Curt stated, Bridge CS6 is the first 64 bit version for both platforms.
    But, your suggestion to check the function of the ESC key in other applications was dead on...It does not work, so Windows 7 needs a bug fix.
    Or your keyboard itself needs a spring clean...

  • Closing JInternalFrame with Ctrl+F4 in windows

    Hi,
    I am using JDK 1.4 in Windows NT.I have a JFrame with menus and a desktoppane.In menu's click item i create a JInternalFrame(say jin) if it is not created and add it to desktoppane.If it is already created i just do a jin.setVisible(true) and use moveToFront of desktoppane.I have written a InternalFrameListener in which i make the jin invisible.When i click the close button in jin it hides correctly.When i click the menu it appears again.But when i use Ctrl+F4 key combination(which we use in Windows to close internalframes) it hides,but when i click the menu it dosen't reappear.I have tried to change the defaultcloseoperation to all values but it dosen't work.Is there a problem in my code or ?
    Thanks,
    Ranga.

    Assuming the above is correct:
    public void keyPressed(KeyEvent e){
    if( (e.isControlDown())&&(e.getKeyCode() == 115 ) )doDefaultCloseAction()); rykk

  • Closing JInternalFrame with Ctrl+F4 not using default close action

    If you have a JInternalFrame and set the default close operation to HIDE, when you close the frame with Ctrl+F4, the frame is disposed instead of hidden. Anyone know if this is the way it is suppose to work, or is this a bug?

    Assuming the above is correct:
    public void keyPressed(KeyEvent e){
    if( (e.isControlDown())&&(e.getKeyCode() == 115 ) )doDefaultCloseAction()); rykk

  • Prevent ESC key from closing movie

    Hi!
    Can anyone please advise me how to stop a movie closing when the ESC key is pressed.
    I have a dialog function that opens another movie to confirm quit.
    I would prefer it to minimize instead of simply closing with no warning.
    Many Thanks
    Sarah

    You set 'the exitLock' to TRUE - check the docs for more details. Also, once the exitLock is true, you can implement an 'on closeRequest' handler to detect your using pressing the ESC key, or clicking the close box on the titlebar.

  • Esc key not working with JDialog

    Hi,
    We are facing a KeyListening problem with JDialog. We developed an application using JRE 1.4.0. When we migrate from 1.4.0 to 1.4.2.The Esc keys(All keys) associated with the JDialog is not listening. Following is code piece is showing the Esc key. The same piece of code is working with 1.4.0 and with lesser versions. U'r help will be appriciated.
    import java.awt.Container;
    import java.awt.event.KeyEvent;
    import java.awt.event.KeyListener;
    import javax.swing.JButton;
    import javax.swing.JDialog;
    import javax.swing.JPanel;
    public class EscDialog extends JDialog implements KeyListener {
         static EscDialog ed = new EscDialog();
         public static void main(String[] args) {
              ed.setSize(200, 300);
              ed.addKeyListener(ed);
              JButton jb = new JButton("Test");
              JPanel jp = new JPanel();
              jp.add(jb);
              Container cp = ed.getContentPane();
              cp.add(jp);
              ed.show();
         public void keyPressed(KeyEvent anEvent) {
              if (anEvent.getKeyCode() == KeyEvent.VK_ESCAPE)
                   System.exit(0);
         public void keyTyped(KeyEvent anEvent) {
         public void keyReleased(KeyEvent anEvent) {
    }

    An example:import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class Test extends JDialog {
        public Test () {
            getContentPane ().setLayout (new FlowLayout ());
            getContentPane ().add (new JLabel ("Press escape to exit..."));
            getRootPane ().getInputMap ().put (KeyStroke.getKeyStroke (KeyEvent.VK_ESCAPE, 0), "dispose");
            getRootPane ().getActionMap ().put ("dispose", new AbstractAction () {
                public void actionPerformed (ActionEvent event) {
                    dispose ();
            pack ();
            setDefaultCloseOperation (DO_NOTHING_ON_CLOSE);
            setLocationRelativeTo (null);
            setTitle ("Test");
            setVisible (true);
        public static void main (String[] parameters) {
            new Test ();
    }Kind regards,
      Levi

  • Want to close  JInternalFrame when user press OR release "Esc" key.

    i want to close JInternalFrame when user press OR release "Esc" key.
    i am trying that
    but nothing print on console
    public class IFTest extends javax.swing.JInternalFrame {
        public IFTest() {
            initComponents();
        private void initComponents() {
            setClosable(true);
            addKeyListener(new java.awt.event.KeyAdapter() {
                public void keyPressed(java.awt.event.KeyEvent evt) {
                    formKeyPressed(evt);
                public void keyReleased(java.awt.event.KeyEvent evt) {
                    formKeyReleased(evt);
                public void keyTyped(java.awt.event.KeyEvent evt) {
                    formKeyTyped(evt);
            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 394, Short.MAX_VALUE)
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 278, Short.MAX_VALUE)
            pack();
        private void formKeyPressed(java.awt.event.KeyEvent evt) {
            System.out.println("formKeyPressed");
        private void formKeyReleased(java.awt.event.KeyEvent evt) {
           System.out.println("formKeyReleased");
        private void formKeyTyped(java.awt.event.KeyEvent evt) {
           System.out.println("formKeyTyped");
    }

    i don ti thanks
    public class IFTest extends javax.swing.JInternalFrame {
        public IFTest() {
            initComponents();
             this.getActionMap().put("test", new AbstractAction(){
                public void actionPerformed(ActionEvent e) {
                    System.out.println("Escape Pressed");
            InputMap map = this.getInputMap(WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
            KeyStroke stroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
            map.put(stroke,"test");
        private void initComponents() {
            setClosable(true);
            addKeyListener(new java.awt.event.KeyAdapter() {
                public void keyPressed(java.awt.event.KeyEvent evt) {
                    formKeyPressed(evt);
                public void keyReleased(java.awt.event.KeyEvent evt) {
                    formKeyReleased(evt);
                public void keyTyped(java.awt.event.KeyEvent evt) {
                    formKeyTyped(evt);
            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 394, Short.MAX_VALUE)
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 278, Short.MAX_VALUE)
            pack();
        private void formKeyPressed(java.awt.event.KeyEvent evt) {
            System.out.println("formKeyPressed");
        private void formKeyReleased(java.awt.event.KeyEvent evt) {
           System.out.println("formKeyReleased");
        private void formKeyTyped(java.awt.event.KeyEvent evt) {
           System.out.println("formKeyTyped");
    }

  • How to close JFileChooser dialog only while using ESC key ?

    Hi All,
    I am using a Frame and from this frame i am calling the JFileChooser via a JButton.
    and using JFileChooser ShowOpenDialog() for open and close .
    while doing ESC operation my Main Frame is getting closed with JFileChooser dialog.
    Can i close only JFileChooser dialog while doing ESCAPE key operation.
    I Have Escape key function in Main Frame file and JFileChooser file( EscKeyEventActionIntialization)
    But while debuging i am not able to catch the esc key action inside EscKeyEventActionIntialization.
    I have attached the code, please suggest me , if i need to do any change .
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    package MainPackage;
    import javax.swing.filechooser.*;
    import java.awt.event.ActionEvent;
    import java.awt.event.KeyEvent;
    import javax.swing.*;
    public class SourceSettings extends javax.swing.JDialog{
        JDialog dialog;
        private javax.swing.JFileChooser jFileChooser1;
        MainFile  mainFile;
        ImageIcon icon = new ImageIcon(getClass().getResource("/Resource/mchpIcon.GIF"));
        /** Creates new form SourceSetting */
        public SourceSettings(MainFile  pMPFS) {
            dialog = new JDialog();
            dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
            mainFile = pMPFS;
            jFileChooser1 = new javax.swing.JFileChooser();
            dialog.add(jFileChooser1);
            EscKeyEventActionIntialization();
            jFileChooser1.setDialogTitle("Browse For Folder");
            jFileChooser1.setFont(new java.awt.Font("Microsoft Sans Serif", 0, 11)); // NOI18N
            jFileChooser1.setName("Browse For Folder"); // NOI18N
        public String getDirctoryPath()
            int retval = jFileChooser1.showOpenDialog(dialog);
            dialog.setVisible(true);
            if(retval  == JFileChooser.APPROVE_OPTION)
                return jFileChooser1.getSelectedFile().getAbsolutePath().toString();
            else
                dialog.setVisible(false);
                dialog.dispose();
                return null;
        public String getParentDirctoryPath()
            return jFileChooser1.getCurrentDirectory().getAbsolutePath().toString();
        public String getOutputDirctoryPath()
            if(jFileChooser1.showOpenDialog(mainMpfs)  == JFileChooser.APPROVE_OPTION)
               return jFileChooser1.getCurrentDirectory().getAbsolutePath().toString();
            else
               dialog.dispose();
               return null;
        private void EscKeyEventActionIntialization()
            Action  ESCactionListener = new AbstractAction () {
              public void actionPerformed(ActionEvent actionEvent) {
                dialog.setVisible(false);
                dialog.dispose();
            KeyStroke stroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, true);
            JComponent comp = dialog.getRootPane();
            comp.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(stroke, "ESCAPE");
            ActionMap actionMap = comp.getActionMap();
            actionMap.put("ESCAPE", ESCactionListener);
    }

    You have a class that extends JDialog and has a JDialog member variable (very confusing), and no main(...) method. How is the class used as a JDialog?
    To get better help sooner, post a SSCCE that clearly demonstrates your problem. Note that this should be executable and should not contain any extraneous code.
    db

  • Windows 7 ESC key stopped working

    I've got a fully patched Windows 7 Professional Desktop computer that I've been using for over 2 years.  Yesterday my ESC key stopped working, which I first noticed when using Outlook and tried to close an open email window.  I checked the keyboard
    by moving it to another Windows 7 computer - works great.  I also noticed that other keyboard shortcuts that utilize the ESC key still work, like for example pressing Ctrl / ESC brings up the Start menu.  The problem is limited to functions that
    operate off the ESC only - like closing an open email in Outlook or closing an open photograph on Facebook.
    I downloaded a keyboard testing app that shows the key not working.  But when I install this program on another computer and move the suspect keyboard - the program shows that it does in fact work.
    I suspect something is wrong at a registry level - some entry has hijacked the key mapping.  I've spent several hours on Google looking at various suggestions - all to no avail.  I've tried updating drivers as a last resort - no change.  Remember,
    the ESC does work when used in a sequence involving multiple buttons.  Any suggestions?

    I've encountered a similar situation regularly: my Esc key just quits working in mid session, and I always forget what the cause/fix is. 
    I have this same keyboard for over 8 years now, and it always works fine, so no, it's not a hardware issue - these issues typically never are. Rebooting the PC always solves the issue, but rebooting a dev workstation, with a gazillion apps open is a PITA.
    Turns out in my case it's always Photoshop CS2 that 'kills' my Escape key; as soon as I close Photoshop, the Esc key functions normally again.
    Another issue I get is the Ctrl/Shift/Alt keys sometimes quit working; again, a reboot always fixes the issue, but rebooting is always a last recourse. Usually I just mash the Caps Lock/Ctrl/Shift/Alt; sometimes it works, sometimes it doesn't and I need
    to reboot...

  • ESC key not working in exe.

    Hi,
    I'm using Captivate 5 and after publishing an exe project, when we view it, I cannot close the full screen published exe project via the ESC key. Nothing happens. I've heard of the Enter key closing out exe files, but not about the ESC key not working.
    Help?
    Thanks!

    Hi there
    Have you ensured that Captivate has been updated with all service releases?
    I could be wrong but I seem to recall a service release fixed this issue.
    Cheers... Rick
    Helpful and Handy Links
    Captivate Wish Form/Bug Reporting Form
    Adobe Certified Captivate Training
    SorcerStone Blog
    Captivate eBooks

  • Problem with Enter key and JOptionPane in 1.4

    Hi,
    I had a problem with an application I was working on.
    In this application, pressing [Enter] anywhere within the focused window would submit the information entered into the form that was contained within the frame.
    The application would then try to validate the data. If it was found to be invalid, it would pop up a JOptionPane informing the user of that fact.
    By default, pressing [Enter] when a JOptionPane is up will activate the focused button (in most cases, the [OK] button) thus dismissing the dialog.
    In JDK 1.3 this worked fine. But in JDK 1.4, this has the result of dismissing the dialog and opping it up again. This is because the [Enter] key still works on the frame behind the JOptionPane and thus tries to validate it again, which results in another invalid dialog msg popping up.
    The only way to get out is to use the mouse or the Esc key.
    Now, in the application I put in a workaround that I was not very happy with. So, to make sure it wasn't the application itself, I created a test which demonstrates that it still misbehaves.
    Here it is.
    import java.awt.Container;
    import java.awt.FlowLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.KeyEvent;
    import javax.swing.AbstractAction;
    import javax.swing.JButton;
    import javax.swing.JComponent;
    import javax.swing.JFrame;
    import javax.swing.JOptionPane;
    import javax.swing.JTextField;
    import javax.swing.KeyStroke;
    import javax.swing.UIManager;
    import javax.swing.UnsupportedLookAndFeelException;
    import javax.swing.WindowConstants;
    * @author avromf
    public class FocusProblemTest extends AbstractAction
         private static JFrame frame;
         public FocusProblemTest()
              super();
              putValue(NAME, "Test");
         public void actionPerformed(ActionEvent e)
              JOptionPane.showMessageDialog(frame, "This is a test.");
         public static void main(String[] args)
              FocusProblemTest action= new FocusProblemTest();
              try
                   UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
              catch (Exception e)
                   e.printStackTrace();
              frame= new JFrame("Test");
              frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
              Container contents= frame.getContentPane();
              contents.setLayout(new FlowLayout());
              JTextField field= new JTextField("Test");
              field.setColumns(30);
              JButton  button= new JButton(action);
              KeyStroke enterKey = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0, true);
              button.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(enterKey, "test");
              button.getActionMap().put("test", action);
              contents.add(field);
              contents.add(button);
              frame.pack();
              frame.setVisible(true);
    }Does anyone have any solution to this problem?

    I know that focus management has changed alot.
    Based on my experimentation a while back, in 1.4 it still believes that the JFrame is the window in focus, even though a JOptionPane is currently in front of it (unless I misinterpreted what was going on). Thus, the frame seems to get the keyboard event and re-invoke the action.
    A.F.

  • Esc key not working in windows 7

    Hi,
    I have a HP Pavilion dv6-4XXX series. It's almost been 2 years I bought this notebook. 
    Recently I faced an issue. The "ESC KEY" has stopped working. However I could find that it's working fine in BIOS but not when I am logged in to windows. I have windows-7 installed.
    Please let me know what could be the issue and the solution for the same.

    Hello siddharthmishra,
    You’re having a problem with the ESC key not working.
    Go to device manager and uninstall the keyboard and restart the computer. This should uninstall and reinstall the driver for the keyboard.
    Here is a link to device manager.
    If the problem has not been happening for very long, you might try a System Restore. This will take the system back to before the problem started happening without affecting any of your files.
    Here is a link to a System Restore.
    Let me know how everything goes.

  • PSE6 blocks Esc key on Vista

    Hi,
    I have a common problem with Photoshop Elements 6 on Windows Vista (both 32bit and 64bit versions):
    It blocks the Esc key in all other applications! (As long as PSE6 is running, pressing the Esc key in any other windows than its own has no function. This is really annoying, as the Esc key is used like the "cancel" button in almost any window.)
    I know the workaround with pressing Shift+Esc - but isn't there any bugfix released by Adobe? Or do they just ignore it and go around blocking keys on all computers...
    -Frank

    See this thread
    http://www.adobeforums.com/webx/.3c051f74/16

  • FCO-00011  The step runRADDBDIF with step key

    hi all
    I got the error message when installing process in RUN ABAP report
    ERROR 2009-02-14 21:11:25.859
    FCO-00011  The step runRADDBDIF with step key |NW_Onehost|ind|ind|ind|ind|0|0|NW_Onehost_System|ind|ind|ind|ind|2|0|NW_CI_Instance|ind|ind|ind|ind|11|0|NW_CI_Instance_ABAP_Reports|ind|ind|ind|ind|2|0|runRADDBDIF was executed with status ERROR .
    Regards,
    Kevin

    Hi Sunny
    thanks you reply
    but how can I uninstall the instance?
    and that means I should entry any password in DDIC?
    attached with the error message as followings:
    ERROR 2009-02-16 10:17:43.093
    FRF-00025  Unable to call function. Error message: Exception condition "WRITE_FAILED" raised. .
    INFO 2009-02-16 10:17:43.093
    RFC connection closed.
    ERROR 2009-02-16 10:17:43.109
    MUT-03025  Caught ERfcExcept in Modulecall: Exception condition "WRITE_FAILED" raised..
    ERROR 2009-02-16 10:17:43.140
    FCO-00011  The step runRADDBDIF with step key |NW_Onehost|ind|ind|ind|ind|0|0|NW_Onehost_System|ind|ind|ind|ind|2|0|NW_CI_Instance|ind|ind|ind|ind|11|0|NW_CI_Instance_ABAP_Reports|ind|ind|ind|ind|2|0|runRADDBDIF was executed with status ERROR ( Last error reported by the step :Caught ERfcExcept in Modulecall: Exception condition "WRITE_FAILED" raised..).
    Regard
    Kevin

  • Use of ESC key to close e-mail

    HI All,
    Is it possible to set up Mail to allow use of ESC key to close an open e-mail ? The best shortcut i can find to do this is cmd-w. All other (non-apple) email applications I have used allow the use of the ESC key.
    Thanks

    Very fast, actually. I too have graphics turned off. HTML of course is already there, as it is part of the message. I would say 90-95% of the spam is trapped and moved to the junk folder by Mail, so the workflow becomes read/delete read/delete .... with an occasional read/reply/send/delete or glance/junk. I can see no reason for actually opening the message in a separate window.
    AK

Maybe you are looking for

  • Error while creating Datasource in Weblogic 9.2

    Hi I have supplied all the connection pool parameters and all and in the last step of deploying the datasouce on a server in the targets section when I am getting the below error Bean already exists: "weblogic.j2ee.descriptor.wl.JDBCPropertyBeanImpl@

  • Wiered problem with FTP

    Hi All, I have configured a simple sender file communication channel (with sender agreement). The error I get in CC Monitoring is <b>Could not process file 'test.xml': com.sap.aii.adapter.file.ftp.FTPEx: 550 jai/: No such file or directory.</b> The p

  • Sql ansi in oracle 8i

    Hi! is possible use left join and right join syntax in oracle 8i otherwise (+) syntax?

  • Where can I download "Vision Remote Panel Engine"

    Hi, I'd like to be able to view a Real-Time application on a remote computer (without LabVIEW installed). I've installed LabVIEW RunTime 8.5.1 and the image that I display (on the web server) in the VI is always black. I found this post: http://forum

  • Is it okay to get about 1-2 charge cycles a day?

    I use my laptop off battery almost all the time. I had a friend tell me to always unplug it when its 100% and then use it until its like 10-20% and then plug it back in. I have 9 cycles after having this laptop for 7 days. Oh, if it counts i dont tak