Suggestion needed: Where to catch the 'Enter' key

Hi,
Could someone give me guidance. Below is the background and question of what I would like to do. (Note: There would be so much code I am hoping that someone can understand this without it but I will look later tonight at your possible responses to determine if I need to add some code snippets.)
BACKGROUND:
I have an application with a JTabbedPane added to the content pane of the JFrame.
The JTabbedPane has five JPanels added as tabs each of which extends ActionListener. When it creates each JPanel it passes itself as the argument (this).
Each of these 'major' JPanel tabs has several (2-4) 'mini' JPanels added to them and all the various JButtons, JComboBoxes, and JTextFields are added to the 'mini' JPanels.
The JComboBoxes and JTextFields are enclosed in my own separate wrapper classes so I can do some special validation, etc.
One of the 'mini' JPanels is always named 'buttonPanel' and is where the 'cancel' and 'continue' JButtons are added. The buttons are registered with an ActionListener and allow access to the next 'major' JPanel after some checks are performed. Right now the buttons are caught by the ActionListener of each 'major' JPanel
I WOULD LIKE TO:
I would like to have the 'Enter' key perform a 'continue.doClick()' on whatever 'major' JPanel is active (there are many validations to be done on each 'major' panel before the continue button can allow the user access to the next tab). There are from 1-3 other buttons in the same buttonPanel as the 'continue' button so if any of them have the focus then the 'Enter' key action should be handled by them.
I would like to have the 'Escape' key perform a 'cancel.doClick()' on whatever 'major' JPanel is active. The 'Excape' key does not have to defer to any other button actions like the "Enter" key does.
Where would I extend the KeyListener? The JTabbedPane has a changeListener method that keeps track of what tab I am on, would this be someplace that could help keep track of what 'major' JPanel continue button should be called?
Thanks very much.
hopi

You can use an InputMap and ActionMap combination to map an action on the JPanel that is currently selected to the Enter key.
This will allow you to add an ActionListener which is called whenever the enter key is pressed. Then you can cycle through the available buttons and determine which on has focus and call doClick on it. The cycling may require you to place all the buttons in an Array or a Vector.
ICE

Similar Messages

  • Help!! I can't find how to get the enter key......

    Hi...
    I am information technology student. I am now first year second semester
    I need help because I don't know how to catch the enter key in JTextField.
    I want to submit the form when user press the enter key in JTextField....
    I only can find KeyEvent.VK_ENTER ( actually that is not what I want)
    Another thing is
    "How to add a JMenuItem into a JMenuItem...."
    I want to do like this.... When you click the "Tools bar" in View item.. another menu comes out...???"
    He he... I hope you all can understand what I mean.. because I know my english is not so good... because I am from Myanmar.
    for(int i=0;i<1;i--)
    System.out.println("Thanks A lot");
    Thu Rein Nyo...
    You also can reply by e-mail.. thanks

    Hi...
    I am information technology student. I am now first
    year second semester
    I need help because I don't know how to catch the
    enter key in JTextField.it can be done easily by adding an actionListener to the JTextField. So when u enter something in the field and press enter the event will be caught and the code which u write in that will get executed.
    Eg:
    JTextField.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    Your code comes here.
    Another thing is
    "How to add a JMenuItem into a JMenuItem...."
    I want to do like this.... When you click the "Tools
    bar" in View item.. another menu comes out...???"I think you are gettin confused with JMenu and JMenuItem. What u need to do is create a JMenu add another JMenu to it and add JMenuItems to it.. and ur problem will be solved.
    He he... I hope you all can understand what I mean..
    because I know my english is not so good... because I
    am from Myanmar.
    for(int i=0;i<1;i--)
    System.out.println("Thanks A lot");
    Thu Rein Nyo...
    You also can reply by e-mail.. thanks

  • U150 Numeric Keypad - Where is the Enter Key

    If you enable the numeric keypad on the U150 keyboard, which key is the Enter key?  I need this for InDesign and other applications, where the Numeric Keypad Enter key has special meaning.

    I see now that it's context dependent. However, when entering text for a search string in the browser, Swiftkey shows a "Send" key instead of "Enter/Return". When I have an Enter/Return key there, I can just press it and the browser starts my desired search immediately. With the "Send" key, I press it and nothing happens other than a space character appearing immediately after the search string! If I press it twice, the browser will finally start my search.
    This is just the wrong context for Swiftkey to have a "Send" key in place of the "Enter/Return" key. In fact, I'd rather have it be an "Enter/Return" key all the time, that has always worked for me in all contexts. So I'm about ready to throw Swiftkey out of the boat, although I've happily used Swiftkey on Android for a couple of years...On Android Swiftkey, the "Enter/Return" key never changes to a "Send" key, so I think that this is just broken on iOS 8. I really don't like it when keys on a keyboard change depending on context, anyways, that just a badly designed user interface.
    If they don't fix it soon I'll be dumping Swiftkey until they do fix it. I really did like Swiftkey on Android, but on the iPad not so much. Maybe I can find another keyboard, other than the Apple keyboard, that works well on the iPad. Bums me out, I was looking forward to being able to use Swiftkey on iOS 8 like I could on Android.

  • Swiftkey keyboard, where is the "Enter" key???

    Simple question...added Swiftkey keyboard in iOS 8 to my iPad, and it gave me a "send" key where there should be an "enter" key. How in the world do I get the "enter" key on my keyboard instead of the "send" key? I can't find that setting anywhere. The keyboard that they show when you pick a theme has an "enter" key, but mine has a "send" key. Useless.
    This is driving me crazy, any hits for the hintless?
    Thanks.

    I see now that it's context dependent. However, when entering text for a search string in the browser, Swiftkey shows a "Send" key instead of "Enter/Return". When I have an Enter/Return key there, I can just press it and the browser starts my desired search immediately. With the "Send" key, I press it and nothing happens other than a space character appearing immediately after the search string! If I press it twice, the browser will finally start my search.
    This is just the wrong context for Swiftkey to have a "Send" key in place of the "Enter/Return" key. In fact, I'd rather have it be an "Enter/Return" key all the time, that has always worked for me in all contexts. So I'm about ready to throw Swiftkey out of the boat, although I've happily used Swiftkey on Android for a couple of years...On Android Swiftkey, the "Enter/Return" key never changes to a "Send" key, so I think that this is just broken on iOS 8. I really don't like it when keys on a keyboard change depending on context, anyways, that just a badly designed user interface.
    If they don't fix it soon I'll be dumping Swiftkey until they do fix it. I really did like Swiftkey on Android, but on the iPad not so much. Maybe I can find another keyboard, other than the Apple keyboard, that works well on the iPad. Bums me out, I was looking forward to being able to use Swiftkey on iOS 8 like I could on Android.

  • My MacBook Pro keyboard is giving trouble. 0,p,;,/ and the enter key needs to be pressed several times before registering. Help me please??

    My MacBook Pro keyboard is giving trouble. The 0,p,;,/ and the enter key, needs to be pressed several times before registering. Help me please??

    If you are still under warranty and/or have AppleCare, call them.  Let them deal w/it.  Out of warranty, your keyboard may need cleaning.  Use a vacuum hose or a can of compressed air to get the dirt out from under the keys.  For instructions to remove the keys if it comes to that check out the following websites:
    iFixit
    TakeItApart
    Search YouTube for Macbook Pro “How To” tutorials.
    If you do not want to DIY, take your MBP to your local AS or an AASP.

  • How can I prevent forms from being prematurely submitted when users click on the  "Enter" key?

    Is there any way that I can prevent Dreamweaver CF submission forms from being prematurely submitted by the user when he/she clicks on the "Enter" key before they have completed the form?  I need the users to finish form and click on the "Submit" key.  I have the "Submit" key action configured as "submit form"

    Thank you!
    Found a solution through Google.

  • The enter key is not working in firefox but it has working fine in chrome and IE so please help me to rid out from this.

    The enter key is not working in firefox but it has working fine in chrome and IE so please help me to rid out from this.

    Hello gokulaan, '''try Firefox Safe Mode''' to see if the problem goes away. Safe Mode is a troubleshooting mode, which disables most add-ons.
    ''(If you're not using it, switch to the Default theme.)''
    * You can open Firefox 4.0+ in Safe Mode by holding the '''Shift''' key when you open the Firefox desktop or Start menu shortcut.
    * Or open the Help menu and click on the '''Restart with Add-ons Disabled...''' menu item while Firefox is running.
    ''Once you get the pop-up, just select "'Start in Safe Mode"''
    '''''If the issue is not present in Firefox Safe Mode''''', your problem is probably caused by an extension, and you need to figure out which one. Please follow the [[Troubleshooting extensions and themes]] article for that.
    ''To exit the Firefox Safe Mode, just close Firefox and wait a few seconds before opening Firefox for normal use again.''
    ''When you figure out what's causing your issues, please let us know. It might help other users who have the same problem.''
    Thank you.

  • Using the enter key on an editable table

    Hi,
    I'm using 11g adf and I can't figure out how to get past this:
    When going through an editable table (with editingMode="editAll") using the enter key, it will stop after a certain number of rows, equal to the value of fetchSize. If I want to go down further, I have to scroll down another way to make it fetch the next set of rows, it won't go to the next row with the enter key. It simply won't execute the query to fetch the next rows.
    Increasing the fetchSize will just delay the problem to a row further down (and decrease the performance since the fetch operation can take quite a bit longer).
    I've tried to put a clientListener on both the table or the inputText fields to intercept the enter key, but that won't work when the table is in editable mode.
    Is there any way to fix this problem?

    Hi,
    I've tried to put a clientListener on both the table or the inputText fields to intercept the enter key, but that won't work when the table is in editable mode.
    The clientListener needs to be on the inputText fields. Then in JS you need to call a server listener which will check if the current row is already at the range end and if calls NextSet (you can provide this as a method binding). Unfortunately after this you will need to PPR the table to show the new rows. This is how I would try it.
    Frank

  • How can I use the enter key instead of tab to change field focus?

    I am using Acrobat 9 Pro.
    We have a fillable PDF where the users enter numbers into fields.  They want to be able to use the <enter> key on the 10-key pad instead of the <tab> key on the keyboard to move the focus to the next data entry field.
    How can I set my PDF so that it recognizes the <enter> key instead of the <tab> key for changing focus?
    Thanks!

    You can use a custom Keystroke script, something like:
    // Custom Keystroke script for text field
    if (event.willCommit && event.commitKey === 2) {
        getField("Text2").setFocus();
    Where "Text2" is the name of the next field. This doesn't disable the Tab key though. For more information, see: http://livedocs.adobe.com/acrobat_sdk/9.1/Acrobat9_1_HTMLHelp/JS_API_AcroJS.88.608.html

  • JFileChooser - activating buttons with the enter key

    Hi All,
    I am trying to figure out how to activate the cancel button in the file chooser by tabbing to it, and than pressing the enter key. I know how to do this in a regular dialog, but I can't seem to get the access I need to the JFileChooser to get it to work there.
    I would appreciate any help.
    Thanks!
    robinste

    The Buttons in the File Chooser by default dont use the Enter Key.
    You must make the Enter key work if you are to use it
    after you tab to get the focus on to it.
    For this to be done you will need to extend the FileChooser
    and change the key listener for the cancel button .......
    Hope t was of some help ............

  • Why i am unable to catch the 'TAB' key press?

    hi
    i have an application where i have 2 text fields and one button in order say t1, t2 and b1.
    on tabbing t1 cursor moves to t2 and on tabbing t2 cursor moves to b1 and on tabbing b1 cursor moves to t1.
    now when i press tab button on any of the component i have written a keyListener for that to catch 'TAB' key using the comparision
    if( e.getKeyCode() == KeyEvent.VK_TAB )
    but its not catching the tab key pressed on any of these 3 components....
    why like this...
    i want to catch the press of 'TAB' key and write some action for it... but unable to catch the 'TAB' key press.
    anyone could help me in this....
    thanx in advance,
    -Soni

    I seem to remember this question being asked before. I think the answer was that the FocusManager intercepts the TAB key. I don't remember the solution but you can try searching the forum.

  • Disabling the enter key

    Hi, I have a jsf page that has an <h:inputText> fileld, and whenever I fill it and press enter the form gets submmited. I want to disable the enter key, so that if the user hits enter nothing will happen. This way the form will only be submmited by clicking a button with the mouse.
    Thank you,
    Komyg

    You can use javascript to do this. The merits of using javascript can be saved for another time. Simply put 'javascript disable enter key' in a Google search and you will find what you need. Here is the link at the top of that list:
    http://www.felgall.com/jstip43.htm
    Good luck.

  • Remove the Enter key binding from a JPopupMenu

    Hi,
    Does anyone know how to remove the Enter key binding from a JPopupMenu?
    So when the popupmenu is showing and you type Enter, nothing should happen and the menu should stay where it is.
    I have tried:
    popup.getActionMap().put("enter", null);
    popup.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "enter");but the popup always disappears.
    Any ideas?
    Cheers,
    patumaire

    First of all, that is not the proper way to "remove" a key binding. Read the Swing tutorial on [How to Use Key Bindings|http://java.sun.com/docs/books/tutorial/uiswing/misc/keybinding.html#howto] for more information.
    However, we still have a couple of problems:
    a) the input map is dynamically built as the popup menu is displayed
    b) the input map is built for the root pane, not the popup menu
    The following seems to work:
    popup.show(...);
    InputMap map = getRootPane().getInputMap(JTable.WHEN_IN_FOCUSED_WINDOW);
    map.put(KeyStroke.getKeyStroke("ENTER"), "none");
    KeyStroke[] keys = map.allKeys();
    for (int i = 0; i < keys.length; i++)
         KeyStroke key = keys;
         Object action = map.get( key );
         System.out.println(key + " : " + action);

  • Pressing the enter key on the keyboard

    Need to know the trigger or the way to attribute code to pressing de enter key on the Keyboard!!!???
    Thanks!!!!!

    Hi Carlos,
    By default, the ENTER key takes the cursor to the next navigable item in the block.
    To override this default behaviour it is necessary to modify the forms resource file to revise the key mapping details.
    Refer to article 209671.1 on Metalink: How to Change / Customize the Key Mappings for 6i and 9i Webforms?
    Read the section 'B: Mapping for ENTER to fire KEY-ENTER-TRIGGER over the Web'
    Regards,
    Monica

  • I just downloaded (updated) Firefox to V 20.0.1 now the "search" does not work, either via the mouse click or the enter key. Windows XP.

    Updated to latest version, V 20.0.1 Now when on the home page the "search" does not function with mouse click or the enter key. Currently running XP Service pack 3. I also have the same problem (after same firefox update at home with my HP laptop running Windows 7.

    You can check if you still have the XML files of the default search engines including Google in the searchplugins folder in Firefox program folder.<br />
    If not then you need to reinstall Firefox.
    Try to use the SearchReset extension to reset some preferences to the default values.
    *https://addons.mozilla.org/firefox/addon/searchreset/
    Note that the SearchReset extension only runs once and then uninstalls automatically, so it won't show on the "Firefox > Add-ons" page (about:addons).
    Try to delete the search.json file and a possible search.sqlite file in the Firefox profile folder.
    *http://kb.mozillazine.org/Profile_folder_-_Firefox
    Firefox will rebuild the search.json file from the default search engines in the searchplugins folder in the Firefox program folder and the searchplugins folder in the Firefox profile folder.
    Do a clean reinstall and delete the Firefox program folder before reinstalling a fresh copy of Firefox.
    Download a fresh Firefox copy and save the file to the desktop.
    *Firefox 20.0.x: http://www.mozilla.org/en-US/firefox/all.html
    Uninstall your current Firefox version, if possible, to cleanup the Windows registry and settings in security software.
    *Do NOT remove personal data when you uninstall your current Firefox version, because all profile folders will be removed and you will also lose your personal data like bookmarks and passwords from profiles of other Firefox versions.
    Remove the Firefox program folder before installing that newly downloaded copy of the Firefox installer.
    *It is important to delete the Firefox program folder to remove all the files and make sure that there are no problems with files that were leftover after uninstalling.
    *http://kb.mozillazine.org/Uninstalling_Firefox
    Your bookmarks and other profile data are stored in the Firefox profile folder and won't be affected by an uninstall and (re)install, but make sure that "remove personal data" is NOT selected when you uninstall Firefox.
    If you keep having problems then also create a new profile.
    *http://kb.mozillazine.org/Profile_folder_-_Firefox
    *http://kb.mozillazine.org/Profile_backup
    *http://kb.mozillazine.org/Standard_diagnostic_-_Firefox#Clean_reinstall

Maybe you are looking for