Manipulating tab focus in JTable ??

Hi ,
I am using a JTable with 3 columns out of which 3rd column is non-editable and gets populated based on the values of first 2 columns.
Default tab behaviour traverses through all the columns including the non-editable column. I want to restrict the tabbing to non editable column and want to move tabbing across the editable columns only.
Not able to figure out the exact API's. CAn anybody please help me out ??
thanks in advance

Code for the class which does that magic. It also works for LEFT, RIGHT, UP, and DOWN arrow keys.
import java.awt.Component;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.Iterator;
import javax.swing.AbstractButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPopupMenu;
import javax.swing.JTable;
import javax.swing.KeyStroke;
import javax.swing.SwingUtilities;
import javax.swing.event.ChangeEvent;
import javax.swing.event.EventListenerList;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.TableColumnModelEvent;
import javax.swing.event.TableModelEvent;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.JTableHeader;
import javax.swing.table.TableCellEditor;
import javax.swing.table.TableCellRenderer;
import javax.swing.table.TableColumn;
import javax.swing.table.TableColumnModel;
import javax.swing.text.JTextComponent;
public class MyTable extends JTable{
protected boolean processKeyBinding(KeyStroke stroke, KeyEvent evt,
                                     int condition,boolean pressed) {
        Component cellEditorComp = this.getEditorComponent();
        // If the editor is a combo box, and the key is down arrow, pass the event to Drop down
        if ((cellEditorComp != null) &&
            (cellEditorComp instanceof JComboBox) &&
            (evt.getKeyCode() == KeyEvent.VK_DOWN))
                return super.processKeyBinding(stroke, evt, condition, pressed);
        // if the current cell is in edit mode, pass the event to editor component
        // for right and left arrow keys
        // For combo box do not pass the event, instead handle left and right arrow key press.
        if ((getCellEditor() != null) &&
        !(cellEditorComp instanceof JComboBox) &&
        ((evt.getKeyCode() == KeyEvent.VK_LEFT) ||
        (evt.getKeyCode() == KeyEvent.VK_RIGHT)))
                return super.processKeyBinding(stroke, evt, condition, pressed);
        // To avoid handling of the keys more than once,
        // the following condition is checked.
        if (pressed)
                return true;
        if ((evt.getKeyCode() == KeyEvent.VK_TAB) &&
           (!evt.isAltDown())) {
                if (evt.isShiftDown())
                        processShiftTabKey();
                else
                        processTabKey();
        else if (evt.getKeyCode() == KeyEvent.VK_LEFT){
                processShiftTabKey();
        else if (evt.getKeyCode() == KeyEvent.VK_RIGHT){
                processTabKey();
        else if (evt.getKeyCode() == KeyEvent.VK_UP){
                processUpArrow();
        else if (evt.getKeyCode() == KeyEvent.VK_DOWN){
                processDownArrow();
        else
                return super.processKeyBinding(stroke, evt, condition, pressed);
        return true;
* Method to select a table cell
public void setSelectedCell(int pRow, int pCol) {
        try {
                this.grabFocus(); 
                this.addColumnSelectionInterval(pCol, pCol); 
                this.addRowSelectionInterval(pRow,pRow);
                this.editCellAt(pRow,pCol);
                if (this.getEditorComponent() != null)
                        this.getEditorComponent().requestFocus();
                // make the cell visible, it may not be visible sometimes.
                scrollRectToVisible(getCellRect(pRow, pCol, true));
        } catch (Exception e) {
                System.out.println("ERROR: attempting to select cell at row " + pRow + " & column " + pCol);
* PROCESS SHIFT + TAB KEY
public void processShiftTabKey(){
     int nRow = this.getEditingRow();
         int nCol = this.getEditingColumn();
         // if the cell is in edit mode, stop it.
         if (this.getCellEditor() != null)
              this.getCellEditor().stopCellEditing();
          int newCol = findPreviousEditableColumn(nRow, nCol);
          while (nCol == newCol){
               nRow--; // check the next row
               nCol = this.getColumnCount(); // to start with last col
               if (nRow < 0){
                    this.transferFocus();
                    return;
               newCol = findPreviousEditableColumn(nRow, nCol);
         setSelectedCell(nRow, newCol);
public int findPreviousEditableColumn(int nRow, int nCol){
        if ((nRow >= 0) &&
             (nRow < this.getRowCount())&&
             (nCol >= 0)){             
              for(int i=nCol-1; i!=-1; i--){
                        if (this.isCellEditable(nRow, i)){
                    return i;
         return nCol;
* PROCESS TAB KEY
public void processTabKey(){
         int nRow = this.getEditingRow();
         if (nRow == -1)
                return;
         int nCol = this.getEditingColumn();
         // if the cell is in edit mode, stop it.
         if (this.getCellEditor() != null)
                this.getCellEditor().stopCellEditing();
                int newCol = findNextEditableColumn(nRow, nCol);
                while (nCol == newCol){
                        nRow++; // check the next row
                        nCol = -1; // to start with 1st col
                        if (nRow >= this.getRowCount()){
                                this.transferFocus();
                                return;
                        newCol = findNextEditableColumn(nRow, nCol);
        setSelectedCell(nRow, newCol);
* PROCESS UP ARROW KEY
public void processUpArrow(){
     int nRow = this.getEditingRow();
     if (nRow <= 0)
          return;
     int nCol = this.getEditingColumn();
     // if the cell is in edit mode, stop it.
     if (this.getCellEditor() != null)
                this.getCellEditor().stopCellEditing();
     setSelectedCell(nRow-1, nCol);
* PROCESS DOWN ARROW KEY
public void processDownArrow(){
     int nRow = this.getEditingRow();
     if ((nRow == -1) ||
        ((nRow+1) == this.getRowCount()))
             return;
     int nCol = this.getEditingColumn();
     // if the cell is in edit mode, stop it.
     if (this.getCellEditor() != null)
          this.getCellEditor().stopCellEditing();
     setSelectedCell(nRow+1, nCol);
public int findNextEditableColumn(int nRow, int nCol){
         if ((nRow >= 0) &&
          (nRow < this.getRowCount())){             
                for(int i=nCol+1; i<this.getColumnCount(); i++){
                  if (this.isCellEditable(nRow, i)){
                    return i;
         return nCol;
}

Similar Messages

  • How do I stop Yahoo mail's popup dialog box from changing the tab focus?

    Hi,
    When I have a tab opened to Yahoo mail and I open a Yahoo email on my other computer or Blackberry, there's a time delay and at some point, Yahoo shifts my browser focus to display a pop-up dialog box that says "You have been disconnected from chat because you have signed into Yahoo! Messenger from another computer." I can't even switch back to the tab I was on without dismissing the popup.
    I'd love it if I could turn off the pop-up, - don't care about the disconnection - but in the meantime, is there some way to prevent Yahoo from changing my tab focus?
    Thanks!

    Hi Douglass,
    You will need to navigate to the following folder.
    /Users/yourusername/Library/Mail/V2/MailData
    and backup the following file... MessageRules.plist
    Open the file in BBedit to confirm your rules are infact inside that particular plist file as Mail will also create backups occasionally.
    Once you reinstall, do a compare/replace with the newly created MessageRules.plist and you should be able to bring your "old" rules into your fresh install.
    as for mailboxes, those are contained within this folder
    /Users/yourusername/Library/Mail/V2/Mailboxes
    and it will be up to you to backup those files and File/Import Mailboxes them into the new install.

  • How do I prevent tab focus from changing when I scroll tabs with the mouse wheel? [SOLVED]

    Whenever I scroll my tabs with the mouse scroll wheel the tab focus changes from the page I'm currently on to the tab being scrolled to. I usually have a large list of tabs open and I depend on being able to scroll tabs without changing page focus to keep myself organized.
    Also, I'd like to disable tab scroll wrapping; Once I've scrolled my tabs to the end I'd like it to stop scrolling, not wrap around to the start of my tabs.
    Is there a way to disable these features and revert to the tab scrolling behaviour of a previous version of Firefox?

    This is not a standard feature and can be caused by an extension.
    Start Firefox in [[Safe Mode]] to check if one of the add-ons is causing the problem (switch to the DEFAULT theme: Tools > Add-ons > Themes).
    * Don't make any changes on the Safe mode start window.
    See:
    * [[Troubleshooting extensions and themes]]
    * [[Troubleshooting plugins]]

  • Tab focus progressing to parent window from popup

    Hi,
    I am using JDeveloper 11.1.1.7.0 version.
    I have a bounded task flow with .jsff fragments and I am trying to call another bounded taskflow(with .jspx files) as "Run As Dialog" from this taskflow.
    Here I am able to set initial focus to the required input element using <af:document> tag's "initialFocusId" property. Up to this, it is working fine.
    When I tried to tab, cursor is moving to next fields as expected. But after completing all the fields and buttons in the popup, tab focus is progressing to the parent window links and buttons.
    Is there a way to block the cursor progression to parent window and make it to rotate within the popup window.
    Thanks,
    Gopal.

    This is a bug in ADF Framework. Filed a bug with ADF Framework and they have accepted this as a bug.
    I'll update this post once I get the resolution from ADF team.

  • Tab focus on af:table

    We have an af:table component on a page. In order to make the page keyboard accessible, we should be able to tab to that component using the Tab key on keyboard. However, when the af:table component is selected using Tab key, it does not get visual tab focus. So it is hard to tell that af:table component is currently selected by the Tab order.
    Is there any way to enforce visual tab focus (dotted lines) around the af:table component?
    Thanks

    We have an af:table component on a page. In order to make the page keyboard accessible, we should be able to tab to that component using the Tab key on keyboard. However, when the af:table component is selected using Tab key, it does not get visual tab focus. So it is hard to tell that af:table component is currently selected by the Tab order.
    Is there any way to enforce visual tab focus (dotted lines) around the af:table component?
    Thanks

  • Tab focus issue with 2 popups open

    Hi!
    I've just got a nasty problem with 2 popups and a tab focus.
    First poup automatically opens second popup and if you press TAB
    key focus goes to the first popup window - underneath the top one.
    As a matter of fact - if you open the second popup by
    clicking on the button in the first window - no problem. It happens
    only if the first window opens second via AS.
    I've found on the internet the following
    article:
    But my joy was premature - this piece code:
    quote:
    SystemManager.activate( popup );
    is simply uncompilable. I tried other methods, like:
    this.systemManager.activate(this);
    without any luck.
    Does anybody know the solution to this problem?
    Thanks in advance!
    Cheers,
    Dmitri.

    Manfred,
    Thanks for your reply. I tried requestFocus() and it gives the same results. Also Sun's 1.4.0 API (http://java.sun.com/j2se/1.4/docs/api/) mentions the following with respect to the requestFocus() method in the JComponent class:
    Because the focus behavior of this method is platform-dependent, developers are strongly encouraged to use requestFocusInWindow when possible.
    That is why I used requestFocusInWindow.
    S.L.

  • TAB focus lost to browser

    Hey Folks.  Have an AS2 file that keeps TAB focus/order properly when using Firefox or Safari but NOT when using IE.  It's fine at first but when I TAB to and select a button the next TAB goes to IE's address bar. This does NOT happen in Firefox or Safari.  Can someone please point me to some info on how to avoid this?

    hi,
    maybe when you reactivate the browser, you reactivate the site(!) and not the applet.
    The applet is only a part of the site and has to be activated, too.
    I guess this is the problem.
    but i got no idea how to fix this.
    sorry.
    cu Errraddicator

  • Changing tab focus with the keyboard

    I've read about changing the tab focus from one page to another programmatically; however, I would like to have shortcut keys to change tabs (like many programs that use CTRL+Tab to change windows within the program).
    I could use an event structure to capture keyboard button presses and then change the value of the tab control, but is there a more straightforward approach?
    Thanks!
    mlloyd

    You can set all other controls not to be tabbed through and the tab control to have its pages tabbed through. That way, when you use tab, only the tab control's pages will be on the tabbing list. This, however, is probably less straightforward.
    I'm not sure what's the problem with the method you outlined. In most cases, if you want something to happen, you will have to code it. This appeares to be one of those cases. You can make a subVI to do the tabbing for you, if you don't want to have to code all of it in your VI. Pass the reference of the tab control into the VI after you detect the event and use that to decide whether to increase or decrease the tab value. Be sure to cycle the number back to the first page when it reaches the end.
    Try to take over the world!

  • Auto tab focus method is not working in iOS devices please share the ideas why its not working?

    Auto tab focus method is not working in iOS devices. Please share the idear i am facing this issue while developing code for devices.

    Hi there,
    I can confirm this bug.
    Not sure if this info is relevant, but this is my experience:
    I am on the FIDO network, and so are two other people I know.
    We all tried blocking numbers, and calls ring right through. Text messages are blocked successfully. (never tried facetime)
    I also tried a ROGERS device running IOS7, and was successfully able to block my phone call from ringing through. HOWEVER, my call was forwarded to their voicemail, I was able to leave a voicemail for the person, and they did get an alert that they had a new voicemail.
    I have not yet had a chance to test this on Bell, Telus, or any other carriers.
    Spoke to Apple, and they advised me to do a hard reset (hold both buttons to shut off and reboot the phone), and if that fails to do an iOS restore.
    I have yet to try this, but hopefully someone will have a better solution.

  • ALV multiple lists: Set tab focus

    Hi,
    I have a report that is producing 4 ALV lists on a screen, each of which is output in its own subscreen.
    However, what I need to be able to do is set the tab focus based on the data selected.
    ie. If no data is found to display in subscreen 1, I want to be able to show subscreen 2 as the initial screen and so on.
    Is it possible to set the tab in this way ?
    Cheers
    Colin.

    Hi Everyone,
    I don't know if you were aware of this but Serdar has written a very good reference booklet on ALV grid and its available on:
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/documents/a1-8-4/an easy reference for alv grid control.pdf
    I'm sure many of us will find this a useful aid to keep on our desks
    Nice one Serdar!
    Best Regards,
    Hafeez

  • Problem with tabbed focusing

    I have a question that I'm guessing has a ridiculously simple answer for you gurus, but I still can't figure this out:
    For some reason, I've had a couple of instances where the OS will go into a "tab focusing" mode, where hitting the tab will switch to each item and put a blue highlight around it, whether it's in a dialog box or the bookmarks bar in Safari. The highlight doesn't always function as something I can activate with the enter key or arrows, though (as in the Shut Down dialog box). The first instance of this (I believe) went away on its own, after performing an OS update. In either case, I'm pretty sure I haven't accidentally turned on something in the system preferences.
    Anyone have a quick and dirty explanation (or better yet, a fix!) for this?

    Hi Chris
    it may be that you un-wittingly hit Shift-F7 which toggles Tabbing between "text boxes & lists only" and "All controls"
    I know I've done this a few times
    iMac G5 rev B   (OSX 10.4.7)  2GB 250GB

  • How to Handled Shift +Tab(Focus) click in radion button?

    Hi,
    I am using Jdeveloper 11.1.2.0.
    My scenario is one radio button having three items(Left,Right,Center). Now my radio button focus is first radio(Left). Now I click the the tab sequence. It will go to the next field, whether it is input field.
    Suppose Now I am come to back ward like shift+Tab it is come to the radio button. Here what is happening mean the focus is going to the Last radio button item(Center), what I want is which radio Item I select Initially ,the Same Place cursor want to go. How to proceed to this. Please give some suggestion to proceed.
    Regards,
    Ragu

    Hi,
    so what you are saying is that the tab focus navigation bypasses the other radio buttons whereas tab back focus navigation doesn't. If this is the case, and due to missing information in your question, try this
    set autosubmit="true" on the radio group so the radio button selection is saved.
    If this doesn't help, please provide information about the implementation of how you created the radio group and which data they are bound to. Chances are that this indeed needs to be filed as a bug but also that it is a problem in your model
    Frank

  • Accessable Tab Focus Menu XML

    The XML menu I have developed is accessable for tab use only when the menu is the only accessable object on stage. When I put other objects on the stage that are tab focused, the XML menu is no longer tab accessable. How do I make my XML menu accessible when other accessible objects are on the stage?

    hey bob, you can enter '''about:config''' into the location bar of firefox, confirm the info notification (in case it shows up), search for the preference named '''browser.search.context.loadInBackground''' & toggle it to true by double-clicking it. that should bring back the old behaviour...

  • CTRL+P requires manual tab focus when printing a PDF within FF4. This worked fine in FF3. Why does it not work any more? Thanks!

    Hi,
    CTRL+P requires manual tab focus when printing a PDF within FF4. This worked fine in FF3 - i.e, you could just select the tab. Why does it not work any more? Thanks!

    Hi
    https://discussions.apple.com/thread/4325038?tstart=0
    CCT

  • How to disable the tab focusing for a JTextField object because those ...

    Hi All,
    Here I need some help. I want to disable the tab focusing( tab index) for a JTextField objects because those objects are set as setEditable(false). Also can u tell me about how to change the tab index orders for JTextFields.
    Many thanks,
    Vijaycanaan.

    I want to disable the tab focusing( tab index) for a JTextField objectsLook through the API and find methods with the word "focus" in the method name.
    Also can u tell me about how to change the tab index orders for JTextFields."How to Use the Focus Sub System":
    http://java.sun.com/docs/books/tutorial/uiswing/misc/focus.html

Maybe you are looking for

  • How to show more than 1 row

    N > iSupplier Portal Full Access > Account (Tab) > Create Invoices > Update Invoices Under "Other Charges" you have "Line Charge Type" of Tax, Freight and Miscellaneous. Freight and Miscellaneous have "Add Another Row" button. I added "Add Another Ro

  • What will I need to upgrade my Macbook Pro's HDD to an SSD?

    I wanted to know what I would need in order to upgrade my early 2011 Macbook Pro's HDD to an SSD. What should I consider before making the change from an HDD to an SSD? Also what are the pros and cons to making this change - excluding the price of th

  • How to change the response of the mighty mouse scroll ball?

    Is there a way to do it? thanks

  • EA6500 as access point?

    Can the EA6500 be set up as an access point connected to a remote router which has a connection to the DSL modem? I want to replace one of my wireless access points with a faster wireless interface, but this will be connected via hard wire CAT-5 cabl

  • Mouse moving to second display when off

    I have a late 2012 iMac running Mavericks with a Samsung SyncMaster as a second display.  When the 2nd monitor is turned off (manually from the power button on the monitor) my mouse pointer will still move to that display.  I personally don't use the