How to detect key navigation in JTable

Hi,
I have a problem with JTable's events. When the user presses the mouse's left button on a cell, a mouseClicked event is generated, and my program works fine. But when the user moves from cell to cell with the cursor keys or the tab key, no mouseClicked event is generated, and my event code doesn't execute. I have seen listeners like TableColumnModelListener, but I don't want two or more events at the same time: i.e. if I go from cell 1,1 to cell 2,2, I just want one event, not one for the column and another for the row. I just want ONE event for "selection change", originated by mouse or keyboard. What should I use?
I'm using Java 1.4.
Thanks.

[url http://java.sun.com/docs/books/tutorial/uiswing/misc/keybinding.html]How to use Key Bindings

Similar Messages

  • Tab Key Navigation in JTable

    Hello All,
    Can anyone please help me with Tab key navigation in a JTable.I
    read all the messages in this group but couldn't implement one.It
    would be a great help if anyone can provide me a working example of how
    to control the tab key in the JTable. I have a JTable with some of the
    columns not editable, I want the focus to be in the first cell and
    whenever the TAB key is pressed, the focus should go to next editable
    cell and select the data in it.For example: if you take a simple table of 4 columns with column 2 not editable, The focus should begin with the first cell(1st column,1st row) and goto (3rd column,1st row) whenever TAB is pressed.It should work in reverse when SHIFT-TAB is pressed.
    I'm new to Java Swing.I would greatly appreciate if anyone can provide me a working example.
    Thanks in advance,
    siddu.

    OK Here is what I have ...
    public class MultipleEditorsPerColumnJTable extends JTable {
    /** Creates a new instance of MultipleEditorsPerColumnJTable */
    public MultipleEditorsPerColumnJTable( int the_column) {
    this.myColumn = the_column;
    this.rowEditors = new ArrayList();
    setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, Collections.EMPTY_SET);
    setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, Collections.EMPTY_SET);
    protected boolean processKeyBinding(KeyStroke ks, KeyEvent e,int condition, boolean pressed) {
    boolean isSelected = false;
    if (ks == KeyStroke.getKeyStroke(KeyEvent.VK_TAB,0)) {
    int selRow = getSelectedRow();
    int rowCount = getRowCount();
    int selCol = getSelectedColumn();
    if (selCol == 1) { isSelected= getCellEditor(selRow,selCol).stopCellEditing();}
    int targetRow = (selRow + 1) % rowCount;
    this.editCellAt(targetRow, 1);
    this.getComponentAt(targetRow, 1).requestFocus();
    return super.processKeyBinding(ks,e,condition,pressed);
    I think I know why the requestFocus() is not working. OK, I have a MultipleEditorsPerColumnJTable (sub of JTale), JTextPane, JButton and JLabel. The textpane, label and button have individual editors and renderers. Each time I want to display a new Row, I re-render these components and add it to the table.
    Now with the above code, it still navigates to the next component in the row/ first column in next row depending on the current column. What am I doing wrong?
    Thanks,
    Praveen.

  • How to detect key board event

    HI,
    How to detect keyboard event (Like CTRL key press shift key press) in Swing�any can any body suggest classes and interface for that�.
    Thanks

    [url http://java.sun.com/docs/books/tutorial/uiswing/misc/keybinding.html]How to use Key Bindings

  • Key navigation for JTable

    I have a JTable and i need to select its rows during key navigation.
    Say i have 23 columns in this table and just for test purposes everytime on keypressed i want to select 2nd row. I am doing it in following way within KeyPressed Event.
    int[] indexes = table.getSelectedRows();
    table.requestFocus();
    int[] cols = table.getSelectedColumns();
    for (int xx=0; xx<cols.length; xx++ )
    table.removeColumnSelectionInterval(cols[xx],cols[xx]);
    table.removeRowSelectionInterval(indexes[0],indexes[0]);
    table.setColumnSelectionInterval(0,22);
    table.setRowSelectionInterval(2,2);
    But this doesn't seem to work on keypressed event although it works fine if i call it from some other place like a button pressed. Any help gurus ???
    TIA

    Sorry i missed to mention what it actually seems to do. It only selected the 1st column when this piece of code is called from KeyPressed Event.
    But when the same code is called from any other place it selects all the 23 columns.
    I will appreciate any help on this bottleneck problem for me.

  • How to detect the key enter with a numerical control without using loop event?

    I want to accept a numerical value only when the key enter is pressed, but without using the event. How to detect the char "enter" with a numerical control?
    Thanks!

    When the user edits a numeric control with a keyboard, its property "key focus" is true. When the user hits enter, key focus becomes false. Poll the property to latch the control valuse at the true-false transition. That won't work if the user modify the control using up and down arrows.
    LabVIEW, C'est LabVIEW

  • How to listen to key press in JTable

    I've been trying to listen to key press in JTable,
    However it only works if the cell is double-clicked.
    If the tab button is use or the cell is single-clicked, nothing happens to the listener.
    Anybody can help me???
    Thanks

    table.getColumnModel().addColumnModelListener(new TableColumnModelListener(){
      public void columnAdded(TableColumnModelEvent e){}
      public void columnMarginChanged(ChangeEvent e){}
      public void columnMoved(TableColumnModelEvent e){}
      public void columnRemoved(TableColumnModelEvent e){}
      public void columnSelectionChanged(ListSelectionEvent e){
        // column selection changed
    table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
      public void valueChanged(ListSelectionEvent event) {
        // row selection changed
    });rykk

  • How do I get key navigation to work in Labview PDA?

    I want to be able to press a key on my Windows CE device and toggle a boolean control on my application.  However, when I set the key navigation for the control to toggle with F1, it doesn't work?  What am I doing wrong?

    Key navigation and using tab to switch between front panel controls are not supported. You can find more information regarding this from the LabVIEW 8 Help under PDA Module >> Creating  PDA VIs >> Designing PDA VI Front Panels.
    If you would like to make a product suggestion that this be supported, I would encourage you to go to ni.com and click Contact NI.
    Jarrod S.
    National Instruments

  • How to detect  collssion for random or Duplicated movie clips

    Hey guys .. i am back with set of query..till now .. key
    press movement a rocket (mc) is moving left right up down in a
    defined stage area. and i am able to generate some fire balls
    randomize falling from top. this is just i am duplicating the movie
    clip(fireball_mc) .... now i want incase or when the rocket (mc)
    touch the fire ball programm shold detect the collsion and generate
    a score board. well for this i have tried a script for two movie
    clips ... wchich is working but ..i don know or i m not gettng the
    logic how to detect the collission for duplicated movie clips...
    well i m just giving the script for oinly 2 movie clips
    coliding...can any one tell me how to do it with randmize or
    duplkicated mcs??
    for 2 movie clip ...
    _root.mc1.onEnterFrame = function() {
    if(this.hitTest(_root.egg)) {
    _root.result="Oh no..... we are dead";
    } else {
    _root.result="we are going fine";
    (this is happening ..but let me know how can i get the same
    result for ranndom mcs)
    hope someone can help me out ...
    i appriciate ur valuable time to read this..
    thanking you

    Hey thx for ur suggestion...but as i said m very much new to
    actionscript (more designer) so i don have much idea... most of the
    things i m doing for this game i m going through lots of references
    then i tried to understand te codes m implmenting them to my
    need..can u explain me little more about arrays u haves asked for
    loops u asked me to use the hittest function..please /.. i will be
    greatfull to u... thx

  • ANSWER: HOW TO DETECT Java Plugin from JavaScript

    I created a new topic because the questions about
    how to detect Java Plugin in browsers are scattered
    thoughout this forum.
    Basically you need to employ two approaches for IE and NS.
    In IE you need to try to instantiate a small applet
    (not your production applet) in order to see if browser
    can do it. if the browser can do it, you can make a
    call applet from JavaScript in order to find version of
    JRE (as well as a host of other things).
    In NS you can write a simple JavaScript which will
    interrogate the browser for all plugins installed. Then
    ypu can make a desicion whether to pass execution to
    the next(or generated) page which hosts your applet,
    or ask the user to download/install a plugin.
    I ecourage everybody to host a plugin on your site
    rather leave default link to it which is generated by
    html converter.
    In order to run sample,
    Prerequisites:
    Java Plugin 1.3.
    If you have a different version of plugin,
    substitute hardcoded plugin version in JavaScript for
    value that you have.
    1. compile java file
    2. put class file in the same directory with html file
    3. load html file into the browser.
    4. press "Check Java Plugin.." button
    5. see it work
    6. examine code
    7. uninstall plugin
    8. repeat steps 1 - 4
    9. see it work
    10. install plugin.
    Sample code follows:
    **********************HTML FILE BEGIN***********
    <HTML>
    <HEAD>
    <!-- Generated by Kawa IDE -->
    <TITLE>Detect Java Runtime</TITLE>
    </HEAD>
    <SCRIPT LANGUAGE="JavaScript">
    var browsername;
    function doNetscape()
    for (i=0; i < navigator.plugins.length; i++)
    for (j = 0; j < navigator.plugins.length; j++)
    if(navigator.plugins[i][j].type == "application/x-java-applet;version=1.3")
    alert("You are running Netscape with Java Plugin 1.3.0 - OK");
    return;
    alert("You are running Netscape\nPlease, install Java Runtime Environment 1.3.0");
    function doMicrosoft()
    var applet = document.myApplet;
    if(applet == null)
    alert("You are running Microsoft Browser.\nPlease, install Java Runtime Environment 1.3.0");
    return;
    var version = applet.getJavaVersion();
    if(version == "1.3.0")
    alert("You are running IE, Java Plugin 1.3.0 installed - OK");
    else
    alert("You are running IE, other plugin installed - mybe OK if later that 1.3.0\nYour version: " + version);
    function getJava()
    var applet = document.myApplet;
    if(applet == null)
    alert("Please, install Java Runtime Environment");
    return;
         alert("JRE Version: " + document.myApplet.getJavaVersion());
    function checkJavaPlugin()
         browsername = navigator.appName;
         if(browsername.indexOf("Netscape")!= -1)
              browsername="NS";
              doNetscape();
         else
              if(browsername.indexOf("Microsoft")!=-1)
                   browsername="MSIE";
                   doMicrosoft();
              else
                   browsername="N/A";
                   alert("Unknown browser: " + browsername);
    </SCRIPT>
    <body>
    <Strong>Check Java Plugin</strong>
    <OBJECT id="myApplet" classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
         WIDTH = 1
         HEIGHT = 1 >
         <PARAM NAME = CODE VALUE = "DetectPluginApplet.class" >
         <PARAM NAME="scriptable" VALUE="true" >
         <embed type="application/x-java-applet;version=1.3"
              code = DetectPluginApplet width = 2 height = 2 MAYSCRIPT = "true" >
         </embed>
         </EMBED>
    </object>
    <FORM>
         <INPUT TYPE="button" value="Get Plugin Version in IE" onClick="getJava()">
         <INPUT TYPE="button" value="Check Java Plugin in NS and IE" onClick="javascript:checkJavaPlugin()">
    </FORM>
    </BODY>
    </HTML>
    **********************HTML FILE END***********
    ***************APPLET FILE BEGIN***********
    import java.awt.*;
    public class DetectPluginApplet extends java.applet.Applet
         public void init()
              add(new Label("DetectPluginApplet"));
    public String getJavaVersion()
    return System.getProperty("java.version");
    **************APPLLET FILE END************

    Try following java script, it works on new browsers (NS 4+, IE5+). For IE you have to enable 'ActiveX objects creation' in security options.
    var agt=navigator.userAgent.toLowerCase();
    var is_major = parseInt(navigator.appVersion);
    var is_nav = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
    && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
    && (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1));
    var is_nav4up = (is_nav && (is_major >= 4));
    var is_ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
    var is_ie5 = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")!=-1) );
    var is_ie5_5 = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.5") !=-1));
    var is_ie6 = (is_ie && (is_major == 4) && (agt.indexOf("msie 6.0") !=-1));
    var is_ie5up = (is_ie && (is_major == 4)
    && ( (agt.indexOf("msie 5.0")!=-1)
    || (agt.indexOf("msie 5.5")!=-1)
    || (agt.indexOf("msie 6.0")!=-1) ) );
    var pluginDetected = false;
    var activeXDisabled = false;
    // we can check for plugin existence only when browser is 'is_ie5up' or 'is_nav4up'
    if(is_nav4up) {
    // Refresh 'navigator.plugins' to get newly installed plugins.
    // Use 'navigator.plugins.refresh(false)' to refresh plugins
    // without refreshing open documents (browser windows)
    if(navigator.plugins) {
    navigator.plugins.refresh(false);
    // check for Java plugin in installed plugins
    if(navigator.mimeTypes) {
    for (i=0; i < navigator.mimeTypes.length; i++) {
    if( (navigator.mimeTypes[ i].type != null)
    && (navigator.mimeTypes[ i].type.indexOf(
    "application/x-java-applet;jpi-version=1.3") != -1) ) {
    pluginDetected = true;
    break;
    } else if (is_ie5up) {
    var javaVersion;
    var shell;
    try {
    // Create WSH(WindowsScriptHost) shell, available on Windows only
    shell = new ActiveXObject("WScript.Shell");
    if (shell != null) {
    // Read JRE version from Window Registry
    try {
    javaVersion = shell.regRead("HKEY_LOCAL_MACHINE\\Software\\JavaSoft\\Java Runtime Environment\\CurrentVersion");
    } catch(e) {
    // handle exceptions raised by 'shell.regRead(...)' here
    // so that the outer try-catch block would receive only
    // exceptions raised by 'shell = new ActiveXObject(...)'
    } catch(e) {
    // Creating ActiveX controls thru script is disabled
    // in InternetExplorer security options
    // To enable it:
    // a. Go to the 'Tools --> Internet Options' menu
    // b. Select the 'Security' tab
    // c. Select zone (Internet/Intranet)
    // d. Click the 'Custom Level..' button which will display the
    // 'Security Settings' window.
    // e. Enable the option 'Initialize and script ActiveX controls
    // not marked as safe'
    activeXDisabled = true;
    // Check whether we got required (1.3+) Java Plugin
    if ( (javaVersion != null) && (javaVersion.indexOf("1.3") != -1) ) {
    pluginDetected = true;
    if (pluginDetected) {
    // show applet page
    } else if (confirm("Java Plugin 1.3+ not found, Do you want to download it?")) {
    // show install page
    } else {
    // show error page
    }

  • Detect key status of '*', '#' & '0' of using getKeyStates() method

    Any know the how to get key status if using getKeyStates() method of GameCanvas object in pressing keys "*", '0' & '#' (as I know, the method just can detect key pressing of number 1~9)? If no, is there any method able to do so (similar function of getKeyStates() but not keyPressed()) or how to modify the method able to function it ?

    Hello,
    Sorry for the confusion... let me try to be more clear...
    So, my test campaign for a specific UUT is composed of about a dozen sequences, which can be run independently. But I created another sequence, to work as a "batch", calling all these dozen sequences.
    Pretty much what it does is:
    1) Call first sequence in new execution
    2) Wait for execution to finish
    3) Check results of execution
    4) Add results to report
    5) Wait 10 seconds
    6) Call second sequence in new execution
    7) So on...
    So, for each new execution, I have a dedicated report, which is exaclty what I want. But for my "batch" sequence, I would like to be able to get a report saying which executions passed or failed, so I don't have to open the reports for each execution individually.
    The way I'm doing this (in step 3 above) is with the following expression:
    ( Find( RunState.PreviousStep.ResultStatus, "Passed", 0, True, False ) >= 0 ) ) ? "Passed" : "Failed"
    This way, anything different than "Passed" would give me a "Failed" result for that execution, and that's fine. The problem is that when one of the executions is terminated before it's finished, the PreviousStep.ResultStatus is giving me "Passed".
    I didn't know about the GetStates() method... Looks promissing! I'll give it a try.

  • Enter key as Tab Key in a JTable

    How can I have the Enter Key act as a Tab Key in a JTable?

    thnx...but I already solved my problem. In case someone has the same problem:
    final InputMap im = table.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    final KeyStroke key = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0, false);
    im.put(key, "selectNextColumnCell");

  • Regarding Tab key Navigation in a page

    Hi,
    I have a requirement regarding the tab key navigation on a page.
    Suppose the focus is on the last field of a page, on clicking the tab key i should go to the first field in the page not the url. i tried using tab index, but the problem is that after coming back to the first field from the last field, on clicking on tab again it does not go on as usual, it suddenly jumps to the url from there.
    Regards
    Krishna

    OK Here is what I have ...
    public class MultipleEditorsPerColumnJTable extends JTable {
    /** Creates a new instance of MultipleEditorsPerColumnJTable */
    public MultipleEditorsPerColumnJTable( int the_column) {
    this.myColumn = the_column;
    this.rowEditors = new ArrayList();
    setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, Collections.EMPTY_SET);
    setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, Collections.EMPTY_SET);
    protected boolean processKeyBinding(KeyStroke ks, KeyEvent e,int condition, boolean pressed) {
    boolean isSelected = false;
    if (ks == KeyStroke.getKeyStroke(KeyEvent.VK_TAB,0)) {
    int selRow = getSelectedRow();
    int rowCount = getRowCount();
    int selCol = getSelectedColumn();
    if (selCol == 1) { isSelected= getCellEditor(selRow,selCol).stopCellEditing();}
    int targetRow = (selRow + 1) % rowCount;
    this.editCellAt(targetRow, 1);
    this.getComponentAt(targetRow, 1).requestFocus();
    return super.processKeyBinding(ks,e,condition,pressed);
    I think I know why the requestFocus() is not working. OK, I have a MultipleEditorsPerColumnJTable (sub of JTale), JTextPane, JButton and JLabel. The textpane, label and button have individual editors and renderers. Each time I want to display a new Row, I re-render these components and add it to the table.
    Now with the above code, it still navigates to the next component in the row/ first column in next row depending on the current column. What am I doing wrong?
    Thanks,
    Praveen.

  • Key navigation

    how can i use Key navigation ( Enter KeY)For two boolean ( Ok1,OK2)in one vi,because it work only for one when irun the program.
    someone can help me with a sample
    Attachments:
    Key.vi ‏54 KB

    Instead of using Key Navigation, try the event structure like in the attached example. I didn't use the Booleans in the example but you can add those as well.
    Attachments:
    Key_mod.vi ‏56 KB

  • How to detect plug-ins path for Photoshop CC?

    Hi
    I downloaded new CC SDK but unfortunatelly in html doc there is not info how to detect a plug-in path for new Photoshop CC. Pdf doc also contains very old info (still for Photoshop 5.0)
    - Could you advice how my installers can detect new Photoshop CC and detect a target place for plug-in installation? Forboth  win and Mac cases.
    - Is CC a pure 64bit windows app or it also can be presented into both C:\Program files and C:\Program files(x86) folders?
    Thanks
    Maxim

    Thank, Bartek, for your responce
    I checked this approach for CS4. In my winRegistry there is not {06870682-6f3c-4b97-9143-f03e85c0 bd3e} key. Should it work only for CC?
    Previously, I checked "HKLM\Software\Adobe\Photohsop" and found all presented PSD versions, like #12 for CS5, #55 for CS5.5 #60 for CS6. And Wow6432Node accordingly
    Will this approach work if I will search for CC the key like "HKLM\Software\Adobe\Photohsop\80\PluginPath" ? (if I had PSD CC I could check it but I dont wan to install it yet for dont break my currect working environment)
    Also, could you advise what it default installation path for Mac? Some like "/Applications/Adobe/Adobe Photoshop CC" ? Will CC have same plug-ins subfolder like previously versions?
    Best regards
    Maxim
    PS. Ilya, it means what I should check bot 32 and 64 bit windows versions and for CC also? 32bit windows version of CC is still available? wot is <version> key for CC? 80? CC? Do you know what is default installation path for CC on Mac?

  • How to detect keystroke and control a digital potentiometer?

    Dear All,
    I want to use PCI-1200 to control a Xicor X9C103P digital potentiometer.
    The procedure is as follows: If the computer detects any keystroke from
    either UP or DOWN arrow keys, it send a chain of digital signals to a
    digital potentionmeter to increase or decrease its resistance accordingly.
    Each keystroke control the potentiometer to change a fixed amount, say,
    around 500 Ohm. How to detect these keystrokes using LabVIEW and
    send to digital potentiometer through PCI-1200?

    If you are refering to the ability to capture user key strokes you will need to add a listener to the class. If is a matter of is it a charater or a number then look into isDigit. Or are you trying to capture Hot-Keys? Please specify and will see if we can help - Bart

Maybe you are looking for

  • How to combine multiple purchased aac files into one aac file

    I recently purchased in iTunes an album consisting of 16 m4a files.  I ended up creating a playlist in iTunes for the songs.  I would like to create one m4a file which combines all and then play it in iTunes.  Is the copy protection preventing me fro

  • OID multiple realms log in issue

    Hi All, I am using OID in a prototype to store users in different organizations. I have done this by creating multiple realms. I am configuring OID with OBIEE so users in OID can log into OBIEE. I am facing an issue when 2 users have the same userid

  • After Effects - Exit Code 7

    Hello. I try to install demo of After Effects 5.5 on my macbook but always I report this. Exit Code: 7 -------------------------------------- Summary -------------------------------------- - 0 fatal error(s), 32 error(s), 47 warning(s) WARNING: DS013

  • N8 message sender problem

    Hi. I have recently got my nokia N8. When I receive a call, the sender name (from my contacts ) gets displayed. however when the same sender sends me a message I don't see his name, I only see his number with the country extension +9613xxxxxx.  Why i

  • Regarding Amount(Dollars) into Words

    hi all,       How we will convert Amount( in terms of Dollars) into Words . I know how to convert Amount (in Rupees) into Words and I know function module SPELL_AMOUNT . but it is not working for Decimals. Can anyone suggest solution for this. Regard