The correct approach to intercept TAB key

Dear Experts,
I have developed a GUI out of javax.swing. The GUI consists of JFrame, several JPanels and javax components, such as JTextField, JLabel, JComboBox, JTable and many more.
Now, I want to change the behavior when user presses TAB key. By default TAB key moves focus from a component to another component. How can I disable this?
I come to two alternatives that I am not sure which one is the correct approach. Could you please advise me?
Alternative 1.
Use key binding on GlassPane.
Alternative 2.
Use event-handling on GlassPane.
If those alternatives are not the best one, could you please provide another alternative?
I have tried the following, but they didn't work...
Action doNothing = new AbstractAction() {
    public void actionPerformed(ActionEvent e) {
        System.out.println("Tab-key is pressed.");
cmbPCode.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0), "doNothing");
cmbPCode.getActionMap().put("doNothing", doNothing);or
getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0), "doNothing");
getRootPane().getActionMap().put("doNothing", doNothing);where cmbPCode is a JComboBox that receives focus when the GUI shows up.
Thanks for your help,
Patrick
Edited by: Patrick_Stiady on Mar 31, 2009 6:51 AM

Thank you for the advice. I am developing an application where the user is not computer literated, so that I have to limit functional key as many as possible and only allow several keys to be active. For example, I don't want TAB key to change the focus, instead I want TAB key to do nothing.
I have tried keybinding, because I think this is the most relevant, but somehow I failed to recognize which component should be bound with keybinding. I have tried to change the input map of the component that receives the focus when the GUI is displayed (cmbPCode) as can be seen on my first post. I also tried to change the input map of the root pane. Both are not successful.
Now, I wonder whether
1. it does not work because the key is not consume()?
2. Or should I use key listener, which I would only use if keybinding were unable to serve my goal?
3. Or should I learn how to intercept key on the glass pane?
4. Is keybinding able to nullify default action, such as changing focus by TAB key? I am asking this, because I'm going to nullify other important key such as ENTER key.
Thank you for any guidance,
Patrick

Similar Messages

  • Want the mouse behave the same way as a tab key

    Hello,
    I am using abap webdynpro. one of my requirements to automatically put the user in insert mode on numeric fields.  That is when the user clicks in a numeric field we want the field to be highlighted.  As soon as the user types something in the field we want the field  to be cleared so that the user overwrites the data.  Basically we want the mouse behave the same way as a tab key.  highlight the field and clear it as soon as you start typing. 
    is this possible?

    As mentioned this is not possible.
    however, I would be wary of trying to overcome a standard functionality "deficiency " like this by implementing an island. If you take this path - all your custom applications will behave differently from the SAP standard ones - which is not really an ideal situation.
    Instead, add your concern to the sticky at the top of this forum - the functionality to "clear" a field (or select all on field on entry which is what is happening with the tab selection) might be added in future releases.
    I think however, that you'll find that the "select all on tab" behaviour is an browser "functionality" rather than anything specifically that SAP has implemented - if you try using a different browser, you may not find the same thing happening (although with the browsers I've checked it does).
    The same thing happens with any HTML forms - just try yourself. e.g.[external site with details on HTML forms and input fields|http://www.w3schools.com/html/html_forms.asp]

  • PJC tab-key navigation problem within bean  (FORMS intercepting tab key??)

    Using Forms 10.1.2.3, IE7, JRE 1.6
    When attempting to navigate within the bean area, it appears as if FORMS is suppressing the keyEvent when the tab key is pressed. This means that I cannot use tab or shift-tab to navigate within the PJC's editable fields/buttons. I can click on them, enter data within them, but tab is somehow intercepted. When I place my PJC within a normal (non-forms) Java window, everything works fine.
    Documentation that I've read seems to indicate that tab should navigate perfectly fine within the bean area.
    Any ideas?

    Hi,
    This is how I did it. Sorry about the formatting, it was OK when I pasted the code fragment in.
    My class contains this in the variable definitions.
    private AWTEventListener keyListener = new DoKey ();
    private class DoKey implements AWTEventListener {
    public void eventDispatched (AWTEvent e) {
    //System.err.println("eventDispatched " + e.toString());
    //System.err.println("eventDispatched source " + e.getSource().toString());
    if ((e instanceof KeyEvent) && (e.getSource() instanceof Component)) {
    * The event was a key pressed event and it was sourced from a Component.
    KeyEvent evt = (KeyEvent) e;
    if (evt.getID() == evt.KEY_PRESSED) {
    if (evt.getKeyCode() == evt.VK_TAB) {
    if (evt.isShiftDown()) {
    ((Component)e.getSource()).transferFocusBackward();
    else {
    ((Component)e.getSource()).transferFocus();
    The listener is enabled when on initialisation
    Toolkit.getDefaultToolkit().addAWTEventListener (keyListener, AWTEvent.KEY_EVENT_MASK);
    Regards, Tony C

  • Why is the itemRenderer null after a tab key in my DataGrid ?

    Hello all,
    I progress in my Flash application Thanks to all for your help !
    But now, I have a very strange problem:
    In my DataGrid, when I click on an item to edit it, in the ITEM_EDIT_BEGINNING event, the DataGridEvent.itemRenderer is set and has the correct value.
    When I use the TAB key, I go on the next column, the ITEM_EDIT_BEGINNING on the newly selected field is triggered, but in that case, the DataGridEvent.itemRenderer is null.
    I need that itemRenderer to have its x, y, width and height.
    Do you have an idea why it's null ?
    Thanks for all

    You may want to feedback to Apple
    http://www.apple.com/feedback

  • How to determine the positioning order when using tab key?

    Hallo,
    in my jspx-page i want to define the order which the cursor jumps when the user is using the tab key.
    i don't know how to? in html there i can use tabindex. which way i must go?
    Any help is appreciated.

    I found that tabindex is not applicable. But i think it is an important point for better handling.
    Is there no easy way to do it?

  • Intercept tab key press

    Hi,
    For my application I need to use a textarea as a code editor
    but my problem is that tabulation key is used to give the focus to
    the next control but I want the tab key to simply insert a
    tabulation.
    Here is my current state:
    I have this in my textarea definition:
    keyDown="onKeyDown(event)"
    and in a script block:
    private function onKeyDown(event:KeyboardEvent):void
    if( event.keyCode == Keyboard.TAB ){
    ta.text+= "\t";
    When I hit the tab key a tabulation is added as planned but
    the focus go to the next control, I tried "event.preventDefault()"
    and "event.stopPropagation()" but both failed, the focus still
    manage to leaves the control. I also tried to change all my
    controls focusEnabled properties to false but now the problem is
    that the event is not event fired when pressing tab, it is fired
    however when I press alt+tab...
    I hope someone has a magical solution since I have no ideas
    left :/

    Hi arjunravinarayan!
    Thanks for anwer!
    The question is that I want no change in the TextArea content.
    When a press the tab key, a tab space is added to TextArea.
    Sergio Martin

  • What is the correct approach to the SAP HR Certifications?

    Hi Experts,
    I was contemplating on taking the SAP HR Certification and wanted to know if it is really useful. I also read a few threads in which people were rushing to take the certification right after their initial training. I personally believe that unless you have the relevant experience in using the system it would not really matter. Could you please give me an insight and also advise on what should be the correct roadmap and if any books would be helpful?
    Thanks,
    Swami

    Hi,
    1. What is the Certification for HR functional consultants?
    Visit [SAP HR Certification Test|http://www12.sap.com/services/education/certification/certificationtest.epx?context=%5b%5bC_THR12_05%5d%5d%7c].
    Visit [SAP Eduction|http://www12.sap.com/asia/services/education/schedule/schedule_IN.htm] under section Human Capital Management ECC 6.0.   
    2. How do I prepare for the Certification? What material do I need and where can I get it, books and eBooks etc?
    You would attend the certification course if you are not an experienced consultant. If you are an experienced consultant and do not want to attend the certification, you will need your company to provide you required documents to submit to SAP.
    You can find books at [SAP Press|http://www.sappress.com/].
    3. Do we need some type of training?
    You will have to attend training if you are not an experienced consultant.
    Also, visit:
    Re: Guidance.
    Regards,
    Srilatha.

  • Don't load tabs until selected option makes firefox sometimes forget the correct address of a tab.

    Observed on the steam marketplace (on activation some older tabs will load an item instead of what used to be a search query listing multiple items, page url changed and no back button available).
    For example:
    The tab url was
    http://steamcommunity.com/market/search?q=RPG+Maker+card
    Browser was then closed.
    Sometimes when I come back to that tab in another session the url changes to one of the listings inside (a page that was visited) with no way of going back to the old url.
    In this example
    steamcommunity.com/market/listings/753/220700-No%20Transparency?filter=RPG%20Maker%20card
    Also note the %20 instead of spaces.
    This happens to about 50% of my tabs. (I have over 50 open)
    I do not know if this applies to other website, but I would assume it would.
    Is this a known issue?

    Hi Ansive, in version 27 this is not a known issue yet. In order to reproduce the issue, can you reproduce this in a new profile without the add ons enabled?
    If so, we could use the help please file a bug with this important information:
    # short description
    # numbered steps to reproduce
    # what is expected and what actually happens
    If you have any questions about this, or would like one of us to help out with the bug please post back with the bug number and one of us would be happy to further investigate when it started to happen.
    Looking forward to your reply!

  • How to save the value from JTextFormattedField using TAB key in lostFocus

    Can you, please help me with this problem:
    I want to have saved new value in JTextFormattedField after I use TAB kye.
    I tried with focusLost, then setting setFocusTraversalKeys etc.
    It looks simple, but !?
    Thanks

    I also tried the JFormattedTextField for the IPAddress Object which I created but it would't work that well I have a bad experience with these TextFields it showed me the formate 0.0.0.0 but when I entered the text in it, it jumps of after tow digits in each column

  • BDT - Question about the correct approach.

    Hi,
    We are already live with SAP CRM but there is a new requirement to add a new checkbox to the BP transaction to be held against each business partner.
    This flag is to be used to flag a Sold-To Party as a certain type of customer.
    If I extend BUT000 by creating a new field on an append structure is this risky as we are live with CRM.
    Or is a better approach to create a new Z table e.g. BP Number and Flag as the fields and enhance the BP transaction this way?
    Many Thanks
    David

    Hi David,
    For your current requirement, it is better if you try adding new fields to Business Partner through Easy Enhancement Work bench, (transaction eewb ).
    Using the Easy Enhancement Workbench (EEW) for business partner in SAP CRM you can easily extend the data model of business partner by new fields or tables and integrate them in the business processes.
    For more information on the steps involved in adding a new field in Business Partner and other useful information, please go through the link provided below:
    [http://help.sap.com/saphelp_crm50/helpdata/en/81/1d5303c023da438e792316c9d25a84/content.htm]
    Wish this is useful to you
    regards
    Srikantan

  • Handling keyTyped events in JTable for TAB key

    In my app, I have a JTable. Some columns are non-editable.
    I have attached a keyListener to the table and have overridden keyTyped() and keyReleased() methods.
    In keyReleased(), I do something depending on the key code. For example: if its the VK_DELETE, I delete the row. If its some other user configured key, then I show a popup dialog where the user can enter some data, etc...
    In keyTyped(), I first check if the column is one of the specific columns. Then I get the keyChar. After this, I show a dialog and pre-populate a JTextField on this dialog with that keyChar.
    My issue is that 'TAB' key events arrive in keyTyped() and not in keyReleased(). As a result, the dialog is shown and the tab takes place inside the JTextfield which is incorrect.
    I would like to ignore TAB keyTyped events. When I look up the keyCode in keyTyped() method, it is 0. So there is no way for me to tell what key was typed.
    How can I ignore TAB events in my keyTyped() method?
    thx

    I now do the following to determine if TAB key has been typed
    public void keyTyped(KeyEvent e) {
    char c = e.getKeyChar();
    if (c == KeyEvent.VK_TAB) {
    Is this correct ?
    Edited by: tsc on Sep 28, 2007 12:40 PM

  • Correct Approach in uploading a file

    Which is the correct approach in uploading an image file.
    Upload the file to the ApplicationServer and save the path in the DataBase
    OR
    Upload the file to the DataBase as BLOB.

    Usually I think you should just be storing the
    location of the image in the database rather than the
    image itself. However there are a couple of
    disadvantages, chiefly that you need to keep the
    database and file system in sync with each other and
    that you don't have the database security to protect
    your images.Perhaps more importantly (depending on your setup) there's the problem of accessing these auxilliary files from different hosts, and keeping the directory tidy. You can, of course, generally access through NFS but then your configuration on different machines had to take account of different file paths.
    And you've got a second set of permissions to worry about.

  • Problem with Tab Key in JFileChooser when Details view is selected.

    Hi all,
    Iam using a JFileChooser in my application.When i click Details option in the JFileChooser the files with the size,Type and modified date are displayed.
    When i am using tab to navigate through the JFileChooser,when the tab enters the area where the files are listed with details,the tab is not comming out of the File List area,instead it is traversing with in the files.How do i come out of the File List area using Tab key.I wanted to make a functionality similar to Windows FileChooser where in if we press Tab it goes to the file list and the next tab focus to Text field and so on.
    Is it possible using JFileChooser??
    Pls Help me,
    Thanks and Regards,
    Ravi

    Hi,
    looking at other threads, I think you will
    have to get the button and modify/remove the tool tip
    as you which.
    this thread might help you, at least the way to get the components in the file
    chooser:
    http://forum.java.sun.com/thread.jsp?forum=57&thread=563002

  • Customize "Tab" key for JTextArea to focus next component.

    Hi,
    I am trying to change the "TAB" key behaviour for JTextArea, by using CustomAction configured via InputMap() and ActionMap(). When the user presses the Tab key, the focus should go the next component instead of tabbing in the same JTextArea component. Here is the code for the CustomAction().
        public static class CustomTabAction extends AbstractAction {
            private JComponent comp;
            public CustomTabAction (JComponent comp) {
                this.comp = comp;
                this.comp.getInputMap().put(KeyStroke.getKeyStroke("TAB"), "TABPressed");
                this.comp.getActionMap().put("TABPressed", this);
            public void actionPerformed(ActionEvent evt) {
                Object source = evt.getSource();
                if (source instanceof Component) {
                    FocusManager.getCurrentKeyboardFocusManager().
                            focusNextComponent((Component) source);
        }This works for most of the cases in my applicaiton. The problem is that it doesn't work with JTable which has a custom cell editor (JTextArea). In JTextArea field of JTable, if the Tab is pressed, nothing happens and the cursor remains in the custom JTextArea exactly at the same place, without even tabbing spaces. Here is the CustomCellEditor code.
        public class DescColCellEditor extends AbstractCellEditor implements TableCellEditor {
    //prepare the component.
            JComponent comp = new JTextArea();
            public Component getTableCellEditorComponent(JTable table, Object value,
                    boolean isSelected, int rowIndex, int vColIndex) {
                // Configure Tab key to focus to next component
                CustomActions.setCustomAction("CustomTabAction", comp);
                // Configure the component with the specified value
                ((JTextArea)comp).setText((String)value);
                // Return the configured component
                return comp;
            // This method is called when editing is completed.
            // It must return the new value to be stored in the cell.
            public Object getCellEditorValue() {
                return ((JTextArea)comp).getText();
        }regards,
    nirvan

    >
    textArea.getInputMap().remove(....);but that won't work because the binding is actually defined in the parent InputMap. So I think you need to use code like:
    textArea.getInputMap().getParent().remove(...);But I'm not sure about this as I've never tried it.I tried removing the VK_TAB key from both the input map and parent input map as shown below. But I still have to press "TAB" twice in order to get out of the JTextArea column in JTable.
                comp.getInputMap().getParent().remove(
                            KeyStroke.getKeyStroke(KeyEvent.VK_TAB,0));
                comp.getInputMap().remove(
                            KeyStroke.getKeyStroke(KeyEvent.VK_TAB,0));after coding this, I am using the setFocusTraversalKeys for adding only "TAB" key as ForwardTraversalKey as given below.
            Set newForwardKeys = new HashSet();
            newForwardKeys.add(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0));
            comp.setFocusTraversalKeys(
                        KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,newForwardKeys);
            Set newBackwardKeys = new HashSet();
            newBackwardKeys.add(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, KeyEvent.SHIFT_DOWN_MASK));
            comp.setFocusTraversalKeys(
                        KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS,newBackwardKeys);The only problem that remains now is that I have to press the "TAB" twice in order to get out of the JTextArea column
    regards,
    nirvan.

  • Correct Approach

    Hi, need some advise here.
    I am required to venture into network programming and have an approach to it. However I am not sure whether it's the correct approach using RMI.
    I am writing a (Server-Host)RMI server which will manage multiple threads. Each of the threads are required to communicating with unique channels provided by the vendor's server program and they will persist throughout the lifespan of the JVM. A RMI client will be written to connect to the RMI server and echo simple requests which translates to specified functionalities provided by the thread objects. The RMI server is also required to perform logging of activities for reporting purpose.
    Here's my question...Which design is better or which is impossible?
    1.
    Program the threads to be exported as remote objects on startup and let the RMI server will act as a form of registry to register a client connect and allocate it to desinated remote thread objects. Let the server focus on other services.
    2.
    Program the RMI server as the main control to receive and interpret all client requests and in turn invoke the required thread methods.
    I need to add further that timing/latency is critical in this instance.
    Thanks!

    bschauwe, thanks for your help!
    I guess as well. My main concern is latency because real-time response is critical for the program to work. Come to think about it, I probably ponder too much about it that I forgot that java Objects are thread-ready to handle such requirements.
    As for the threads to the vendor's server, each of the threads is suppose to open up a single channel to a unique device managed by the vendor's server. The vendor has provided the API to connect and use their devices via the server. I wanted to use threads to managed response time and at the same time perform some sort of queue like you mentioned to ensure that only a single client is connected to each of the channels opened. All this is part of a bigger implementation where users can perform real-time supervising from the server side.
    Right now, I just want to get the client/server implementation up and running.

Maybe you are looking for

  • Is it possible to identify the user?

    Hi, I know that I can check identity.name to see who the user is. But it seems that this property is only available during console, batch, menu and app initialization events. I have a date that is supposed to auto fill if it is blank. I want it to wo

  • How to Make DataGrid configured to act only on a Specific column only a Row

    Hi, I am having a DataGrid which has been populated with a search result data from DataBase . Say for example  CustomerID         Name             Email 100                       Ravi              [email protected]   Now my requirement is When the us

  • Mountain Lion dictation on Flash player

    Apple says OS X now supports Dictation. So wherever you can type, you can use your voice instead. Dictation does not work on text boxes in Flash Player though. Is there any way to fix this?

  • Openssh 3.18.1 on Solaris 8: sftp connection closed

    Hi, to setup a secure environment for file transfer, I have installed the following packages in my solaris 8. - openssh-3.8 - openssl-0.9.7d-Solaris8-local - prngd-0.9.26-Solaris8-local - tcpwrappers-7.6-Solaris8-local - zlib-1.2.1-Solaris8-local I d

  • Someone used my account to download stuff.  Who can I contact?

    If someone used my account and I received a receipt for thing I didn't buy, what can I do?