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.

Similar Messages

  • Override "crtl + tab" key behaviour with "tab" key for JtextArea .

    I am trying to override the "crtl + tab" key behaviour for JTextArea with "tab" key plus add my own action. I am doing the following.
    1. Setting Tab as forward traversal key for the JTextArea (the default traversal key from JTexArea is "crtl + Tab").
    2. Supplementing the "crtl + Tab" key behaviour with my custom behaviour.
    For the point 2 above, I need to get hold of the Action represented by the "crtl + Tab" key so that I could use that and then follow with my own custom action. But the problem is that there is no InputMap entry for "crtl + tab". I dont know how the "crtl + tab" key Action is mapped for JTextArea. I used the following code to search the InputMap.
                System.out.println("Searching Input Map");
                for (int i = 0; i < 3; i++) {
                    InputMap iMap = comp.getInputMap(i);
                    if (iMap != null) {
                        KeyStroke [] ks = iMap.allKeys();
                        if (ks  != null) {
                            for (int j = 0;j < ks.length ;j++) {
                                System.out.println("Key Stroke: " + ks[j]);
                System.out.println("Searching Parent Input Map");
                for (int i = 0; i < 3; i++) {
                    InputMap iMap = comp.getInputMap(i).getParent();
                    if (iMap != null) {
                        KeyStroke [] ks = iMap.allKeys();
                        if (ks  != null) {
                            for (int j = 0;j < ks.length ;j++) {
                                System.out.println("Key Stroke: " + ks[j]);
                }In short, I need to get the Action associated with the "crtl + tab" for JTextArea.
    regards,
    nirvan.

    There is no Action for Ctrl+TAB. Its a focus traversal key.

  • I can not use the tab key to move to the next field or use the shift and tab to move to the prior field in forms.

    After updating to 7.0.1 I can not always use the tab key to move to the next field or use the shift and tab to move to the prior field in forms. This always worked in previous versions and it's much needed for my type of work. Does anyone know of a setting to activate this? If not can the Firefox developers work on this issue (please). I love Firefox but desperately need this feature to work correctly. Thanks!

    I tried in safe mode and the tab key worked just fine. I'm not sure about all web forms I've only recently updated to 7.0. The wen form I was using was for appraisal purposes and it has multiple data fields to fill in and also drop down menus to select from. Might I always have to use Firefox in safe mode to be able to utilize the tab between field feature? Thanks for your help!

  • No question.  I just wanted to thank whomever told me to hit the TAB key for resolving my issue.  I guess I must have inadvertently hit TAB without realizing it.  Thank you very much!

    No question.  I just wanted to thank whomever told me to hit the TAB key for resolving my issue.  I guess I must have inadvertently hit TAB without realizing it.  Thank you very much!

    I'm not sure if I did anything to cause this; if I did, I don't know how to undo it.  The format of my library screen has changed.  Across the whole screen is a group of 3 photos from my last import, with the one I have chosen highlighted.  I can still se

  • Using TAB to focus next component in a JTextArea

    hello everybody,
    I would like to use the TAB-key in a JTextArea to focus the next component in my frame.
    I tried to use an KeyListener which calls an instance of javax.swing.FocusManager with the method
    focusNextComponent(Component c).
    My problem is, that - allthough I call consume() for the KeyEvent - the TAB is displayed im my JTextArea........
    how can I solve this, that the TAB is NOT visible?
    (plaese excuse my bad english )
    Thanks Chris

    The way to do it is use setNextFocusableComponent(Component c)
    so as you create each component, you can set the order that the tab key will give focus.
    eg
    JButton b1 = new JButton();
    JButton b2 = new JButton();
    b1.setNextFocusableComponent(b2);
    etc...
    The tab won't be displayed in the JTextArea then,.
    James

  • How to use tab key with JTextArea to shift focus

    Hi
    My problem is simple as whenevr i use tab key in my JTextArea, instaed of shifting focus to next component, it adds a tab space to my text.
    How do i shift focus out of my JTextArea.
    Ashish

    you can also redefine the textarea's TAB Key behaviour. The tutorial has a good example for that - better than i would be able to describe :-)
    look at http://java.sun.com/docs/books/tutorial/uiswing/misc/keybinding.html

  • TAB key for lyrics in score editor not working anymore!

    I have been editing music for score printing in LOGIC for ever. Suddenly the TAB key won't take me to the next note, but finishes the inputting. I never get beyond the first syllable! I have even disabled the key command for TAB in other editors to make sure they don't clash - but no change. Can anyone help?
    Christoph

    Have you tried without memory card to se if same result in case of possible corruption?
    Suggest that you backup essential data with Nokia Suite and return device to "Out of box" state by keying in *#7370# followed by 12345 (default Nokia lock code unless altered by user).
    Happy to have helped forum in a small way with a Support Ratio = 37.0

  • Can I disable TAB key for Flash?

    Hi All,
    Can i disable TAB key actions in flash? That is i dont want
    the focus to get transferred from one button to another on clicking
    TAB key. Im using my SWF in an MFC application. Even if the MFC
    developers trap the TAB key, it doesnt affect flash - the tab key
    works for flash. I will have to do something in flash.
    I tried _focusrect = false; but it doesnt satisfy me
    requirements.
    Regards
    Roshan

    Hi niki,
    That would do the thing. Thanks a lot.
    Regards
    Roshan

  • Disabling TAB key for specific users

    Good day,
    I am new to SAPand the company will start pretty soon using SAP B1 8.8. We are facing the problem of disabling the TAB key function which give access to a complete list of some tables (in the particular case of financials, all G/L accounts) which is considered confidential and should not be available to any employee. Our actual SAP consultant says that the only solution is to make a special chargeable modification to standard SAP. I find it strange that SAP gives such an open an uncontrolled access to such vital information of the company. I am sure some one on this forum will give me a practical, elegant solution built in SAP authorization mecanism.

    Hello,
    Yes we can do it by Addional authorization
    You can do it by Additional Authorization windows using by Form ID.
    and then goto general authorization select Additinal Athorization as (No authorization) for selected user.
    now selected user can not open Buisness partner on any transaction form .
    then Make a Query for selected BP for selected User and set in on that field .
    1>
    First make new Authorization in Additional Authorization Creator window.
    And select Edit button fill 10001 as form ID.
    OK
    2 >
    Goto General Authorization select perticular user and select same Subject which was created in Additional Authorization window setup. and give no authorization for selected user. ok
    3.Make a FMS from OCRD ,but first you should make filter in master for selected user in SAP. so with the help of we can filetr the record on transaction .
    4.After make FMS with then help of UDF set it in where you want .
    Now Your system is ready for your client requirement.
    Please visit this link
    Re: BP according to user
    Thanks
    Manvendra Singh Niranjan

  • Tab key for screen capture

    Hi All,
    Cap2 takes a new screen capture when we hit the Tab key. Is
    there a way to disable that?
    Thanks in advance - Vijay

    Hi,
    I can see that the norm for most is to take a new screen grab
    when hitting Tab; however, on a project that we are workign on, we
    are narrating information about a set of fields in an application,
    and prefer to ffill them all in on one slide.

  • Tab key for safari documents

    I'm using Google Docs live online and can't find the Tab key on my keyboard. There are a few more I can't find either. I've seen the comments so I know you already know which ones I'm talking about. Can we integrate ALL the features of a normal keyboard into my phone's keyboard please? My partner has a pc-based dinosaur that figured this out. Hook a sister up, I got books to write. Hate to have to switch back to PC based phone, but I will if this hiccup isn't fixed.

    You might want to let Apple know here:
    http://www.apple.com/feedback/

  • Tab key for iPad?

    It seems like a simple soulotion to the lack of a tab key on Ipad would be to alow the space bar to tab when ALL CAPS was on...

    You might want to let Apple know here:
    http://www.apple.com/feedback/

  • ADA 508 Compliance Workflow Overview (tab key for navigation / WebAim Toolbar)

    Hi,
      I've been assigned to update interactive training for a State agency..... with of course, an emphasis on ADA / 508 compliance.
    So, before I pinpoint my two questions/scenarios, here is a basic, initial attempt at providing an overview of ADA compliance workflow in Captivate and beyond. 
    PS - useful Captivate forum urls are at the end of this post. I'm using Captivate v.6
    ADA Compliance Workflow Overview:
    1. All assets need an alt tag and conceivably a description > highlight the asset, like a pic, and click the Accessibility button under Properties.
    2. Create slide notes for each slide > load slide, highlight no assets and click the Accessibility tab under Properties. Copy and paste your notes > for screen readers.
    3. Need closed captioning for video/audio content > I use Camtasia for CC and will use the JW player for screen reader of video content.
    4. Interactivity needs to be accessible via the tab and enter keys.
    What else am I missing?
    Question 1
    My question targets how to get the enter key to initiate after a successful tab. To be clearer.... I hit tab and I can navigate through all the buttons in the correct order, but hitting enter provides no action. I am gettining the yellow highlights around buttons when I tab through. Everything works very well when using the mouse, but blind users don't use mice.
    I did create my own animation buttons in Flash and imported them in as animations. I then placed a Click Box behind the button animation to engage the rollover action. Could this be causing problems? The prebuilt (and clunky looking) buttons on the quizzes do work (ie) tabbing to them and hitting enter provides effective navigation.
    I'm opting not to use the playback control skin, only my Flash nav bar.
    Question 2 (Scenario 2)
    I have downloaded the WebAim Toolbar feature designed for FireFox, used to check ADA compliance issues.
    I am getting this error message:
    A frame does not have a title attribute or value. Okay... I bet I can fix this via the .html file or via the standard.js file??
    and these warnings:
    Alert: Javascript in head - A javascript element is present in the page head section.
    Alert: Flash - A Flash object is present.
    Does anyone know if these alerts are worth fixing?
    Obviously Captivate is going to pump out, or rather publish... javascript elements, but is this bad in the page head section?
    And..... of course a Flash object is present...Captivate produces Flash / Shockwave files.
    I'll obviously ask the programmers at WebAim for guidance as well. As always any help would be appreciated and Tanks in advance.
    http://forums.adobe.com/message/117985#117985
    http://gneil.blogspot.com/2008/09/target-6-million-settlement-is-your.html
    http://kb2.adobe.com/cps/403/kb403160.html
    http://forums.adobe.com/message/3515968#3515968
    Screen grabs are attached.
    Thanks, Calif Dreamin'

    Hi,
      Attached is my zipped project file. I did create my own buttons in Flash - this might be the problem. I have only been problem solving with navigation on the first four slides.
      To clarify, hitting the Enter key does engage navigation, however I’m having difficulty controlling the navigation so that it goes to the correct location.
      I’m using Captivate v.6 / publishing SCORM 1.2 / Using IE to deliver via the SyberWorks LMS.
    Here is question 1:
    Question 1
    My question targets how to get the enter key to initiate after a successful tab. To be clearer.... I hit tab and I can navigate through all the buttons in the correct order, but hitting enter provides no action. I am getting the yellow highlights around buttons when I tab through. Everything works very well when using the mouse, but blind users don't use mice.
    I did create my own animation buttons in Flash and imported them in as animations. I then placed a Click Box behind the button animation to engage the rollover action. Could this be causing problems? The prebuilt (and clunky looking) buttons on the quizzes do work (ie) tabbing to them and hitting enter provides effective navigation.
    I'm opting not to use the playback control skin, only my Flash nav bar.
    Thanks for reaching out!!
    Thanks,
    Bill Farrell  (aka Calif Dreamin’)

  • Left mouse tab key for HP 584037-001

     I have a HP 584037-001 laptop computer with the left mouse tab missing. Do you know where I can purchase this tab

    im not finding anything by that number,can yout tell me a model please?

  • Moving the Focus with the TAB key in a JTextArea Component

    Dear Friends,
    I have exhausted all options of moving focus from JTextArea to next component. I have also tried all suggestions available in this forum. But i'm not able to solve my problem. Can any one help me.
    Thanx in advance.

    I had the same problem before. Here is what i did.
    JTextArea txtArea = new JTextArea(2,15);
    Set forwardTraversalKeys = new HashSet();     
    forwardTraversalKeys.add(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0));          
    txtArea.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,forwardTraversalKeys);          
    Set backwardTraversalKeys = new HashSet();          
    backwardTraversalKeys.add(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, InputEvent.SHIFT_MASK));          
    txtArea.setFocusTraversalKeys( KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, backwardTraversalKeys);
    JScrollPane scrollPane = new JScrollPane(
         txtArea,
            JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
            JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    // the scrollbar of the JScrollPane is focusable that's why it requires
    // another TAB key to transfer the focus.
    scrollPane.getVerticalScrollBar().setFocusable(false);

Maybe you are looking for

  • Time-dependent Vendor Master & Handling Special Characters

    Hi, I need to extract time-dependent Vendor Master. 1. The data source for <b>0VENDOR</b> does not have fields to hold the valid date range. 2. Does the Master data in R/3 for Vendors will hold the valid date range? 3. The text for <b>0VENDOR</b> pro

  • Creating a new schema

    This may sound really simple, but I would like to create a new schema within my 9i database. How do you do that? I have found how to add just about everything else, but not schemas. Thanks

  • Why can't I lookup phone numbers using my iPod Touch?

    When I google "Pizza Hut" on my iPod Touch (using Safari), it finds the nearest Pizza Hut to my house, but instead of displaying Pizza Hut's phone number, it display an icon that says "Call".  When I press on that icon, nothing happens.  Can I get my

  • HT2731 I want to sWet up a second apple ID using the same email address.  How is this done?

    I want to set up a second apple I'd using the same email.  How do I do this?

  • Time Statement

    Hi experts, Related time statement on ESS portal (EP 6.0 SP20 ERP2004), 1. I have activated PYXXFO_SAP_TIM_99_0001  in "smartforms" t-code 2. Activated SAP_TIM_99_0001 3. Assigned the form in HRFOR feature. It worked before, now the system is throwin