How to distinguish is cell get key event or mouse event in table?

Hi!
I have a JTable.
1.Select cell and double click. As result caret is show
2.Select cell and start type. As result caret is show
How distinguish is caret is show, because cell get mouse event or key event?
Thank you.

Hm ...
the problem with the key events is, that they are partically taking place in an editor component - but the double click of the mouse clicked on a cell, which is not currently edited, can be get by a MouseListener added to the JTable.
My idea to that is as follows - hold the double_clicked state in a boolean variable hold by your JTable subclass - it is set by a MouseListener added to the JTable - and reset by the overwritten prepareEditor(...) method. This method should do the following:
// say, double_clicked is a boolean field in your JTable subclass
public Component prepareEditor(TableCellEditor editor,int row,int column) {
Component c = super.prepareEditor(editor,row,column);
if ((!double_clicked)&&(c instanceof JTextField)) { ((JTextField) c).setText(""); }
double_clicked = false;
return c;
}now you have only to implement an add a MouseListener to your JTable subclass which detects this double click and sets the double_clicked field accordingly.
This is an idea on the fly - hope it is helpful for you.
greetings Marsian

Similar Messages

  • Getting key events without a jcomponent...

    Is it possible to get key events without adding a keylistener to a jpanel? I want a class of mine to manage input of it's own, but it has no reference to a jpanel. They don't necessarily have to be KeyEvents, but just some way to detect if a key has been pressed (like the arrow keys). How can I do this? Thanks.

    Lots of components can listen for key events.
    What does your class subclass?It doesn't subclass anything. I am creating a custom menu system for my game using images I have made for the tileset. I would like it to handle some keyboard events of its own. (Like if the down arrow is pressed, it will move the focus down to the next component on its own). Right now I am currently passing the key events from my fullscreen jpanel to the menu class and it is handling them that way. Thanks.

  • How do i able to get data for unit price using RSEG table?

    Dear All,
    How do i able to get data for unit price in RSEG table?

    Hi Thiru,
    Please check the logic in thread http://scn.sap.com/thread/1347964
    Hope this helps.
    Regards,
    Deepak Kori

  • Getting Key Events during animation loop

    I'm having a problem recieving Key events during my animation loop. Here is my example program
    import java.awt.*;
    import java.awt.image.BufferStrategy;
    import javax.swing.JPanel;
    import javax.swing.ImageIcon;
    import javax.swing.JFrame;
    import java.util.ArrayList;
    import java.awt.event.*;
    import java.util.Iterator;
    import GAME.graphics.Animation;
    import GAME.sprites.MainPlayer;
    import GAME.util.MapData;
    import GAME.input.*;
    public class ImageTest extends JFrame {
        private static final long DEMO_TIME = 20000;
        private Animation      anim;
        private MainPlayer     mPlayer;
        private MapData               mapData;
        private InputManager      inputManager;
        private GameAction moveLeft;
        private GameAction moveRight;
        private GameAction exit;
        public ImageTest()
         requestFocus();
         initInput();
         setSize(1024, 768);
         setUndecorated(true);
         setIgnoreRepaint(true);
         setResizable(false);
         loadImages();
         anim = new Animation();
            mPlayer = new MainPlayer(anim);
            setVisible(true);
            createBufferStrategy(2);
            animationLoop();
         // load the player images
         private void loadImages()
              // code that loads images...
         // Initialize input controls
         private void initInput() {
            moveLeft = new GameAction("moveLeft");
            moveRight = new GameAction("moveRight");
            exit = new GameAction("exit",
                GameAction.DETECT_INITAL_PRESS_ONLY);
            inputManager = new InputManager(this);
            inputManager.setCursor(InputManager.INVISIBLE_CURSOR);
            inputManager.mapToKey(moveLeft, KeyEvent.VK_LEFT);
            inputManager.mapToKey(moveRight, KeyEvent.VK_RIGHT);
            inputManager.mapToKey(exit, KeyEvent.VK_ESCAPE);
        // Check player input
        private void checkInput(long elapsedTime) {
            if (exit.isPressed()) {
                System.exit(0);
            if (mPlayer.isAlive()) {
                float velocityX = 0;
                if (moveLeft.isPressed()) {
                    velocityX-=mPlayer.getMaxSpeed();
                if (moveRight.isPressed()) {
                    velocityX+=mPlayer.getMaxSpeed();
                mPlayer.setVelocityX(velocityX);
        // main animation loop
        public void animationLoop() {
            long startTime = System.currentTimeMillis();
            long currTime = startTime;
            while (currTime - startTime < DEMO_TIME) {
                long elapsedTime =
                    System.currentTimeMillis() - currTime;
                currTime += elapsedTime;
                checkInput(elapsedTime);
                mPlayer.update(elapsedTime);
                // draw and update screen
                BufferStrategy strategy = this.getBufferStrategy();
                Graphics2D g = (Graphics2D)strategy.getDrawGraphics();
                if (!(bgImage == null))
                     draw(g);
                     g.dispose();
                     if (!strategy.contentsLost()) {
                         strategy.show();
                // take a nap
                try {
                    Thread.sleep(20);
                catch (InterruptedException ex) { }
        public void draw(Graphics g) {
            // draw background
            if (bgImage != null)
                         // draw image
                 g.drawImage(mPlayer.getImage(), (int)mPlayer.getX(), (int)mPlayer.getY(), null);
    }My InputManager implements KeyListener. When running print statements on my Key events, they are not being called until after the animation demo is done running. Can someone help me with getting the Key events to update during the animation loop? Thank you!

    I've used the post from Abuse on the following thread with success. Maybe it will clue you in to what you might be doing wrong:
    http://forum.java.sun.com/thread.jsp?forum=406&thread=498527

  • Not getting key events.

    Okay have a really odd issue. I have a frame that contains a custom panel that contains a custom canvas. I it setting the focus to the canvas when it opens but I don't seem to be getting key strokes!
    When you change the focus from the frame to another window and click back again you do get the keystrokes but the request focus call seems to only sort of work!
    Any suggestions?

    lwatcdr wrote:
    Already did that and not joy.
    The odd thing is that it used to work and I can not figure out for the life of me why it stopped!
    I have started to move the application over to Swing so some of the dialogs are now Swing with the main window still in AWT. I am working on porting that part to Swing but it is a big dynamic custom document so it is taking a while.Let's just quit with the guessing then, post your code.

  • How to capture backspave and delete key events

    Hi ,
    i would like perform some javascript code on pressing backspace or delete key.
    initially i thought of adf clientlsitener keypress event.but this is not capturing backsapce key event
    what is the alternate way capture backspace or delete key event?
    please help

    Hi
    the following script cancels the input event when the back key is pressed
           function keyTrap(inputEvent){
             var keycode = inputEvent.getKeyCode();
             if(keycode ==8){
               inputEvent.cancel();
           }Use a clientListener
            <af:inputText label="Label 4" id="it7">
              <af:clientListener method="keyTrap" type="keyDown"/>
            </af:inputText>Frank

  • How to distinguish the field on which event is triggered? (ABAP Web Dynpro)

    I have an application where there are multiple input fields in the layout. After the user clicks search help for the input field and selects a value, some action has to be performed for each input field. Currently, I am coding the required action in "WDDOMODIFYVIEW" method. This method will be called whenever there is any action on any input field (as its name says), but how can I distinguish on which input field the method is triggered? or How can I know on which field the search help has been triggered?
    or I would be happy to implement any other solution if available.

    HI Deepak Dakshinadi  ,
    You can implement OVS in your input field.
    In the event ON_OVS you will get the value of the attribute  OVS_CONTEXT_ATTRIBUTE which can give you the id of the input field in which OVS is implemented.
    I think by using this you can distinguished among your input field and based on which you can do your particular coding.
    Check the link for implementing OVS.
    http://wiki.sdn.sap.com/wiki/display/WDABAP/ABAPWDObjectValueSelector(OVS)
    and check the forum to get the id of the field of that particular search help triggered.
    Re: More than 1 OVS in 1 View

  • Do not get key events when HContainer object is added to HScene

    Experts,
    Please help, I am missing something simple.
    I am creating an container (mCurrentContainer) with some buttons in them as follows,
              mRecListButton = new HTextButton("List", curX, curY);
              add(mRecListButton);
              // Setup a recording
              curY += V3Button.mHeight + gap;
              mRecButton = new HTextButton("Record", curX , curY);
              add(mRecButton);
              // Shows the list of scheduled recordings
              curY += V3Button.mHeight + gap;
              mScheduleRecButton = new HTextButton("Schedule", curX , curY);
              add(mScheduleRecButton);
              // Shows the list of Series Recordings
              curY += V3Button.mHeight + gap;
              mSeriesRecButton = new HTextButton("Series", curX, curY);
              add(mSeriesRecButton);
              mCurrentSelectedButton = LISTVALUE;
              mRecListButton.setFocus();
    Then I am creating a scene,
              HSceneFactory factory = HSceneFactory.getInstance();
              HSceneTemplate sceneTemplate = new HSceneTemplate();
              sceneTemplate.setPreference(HSceneTemplate.
                             SCENE_PIXEL_DIMENSION,
                             new Dimension(640, 400),
                             HSceneTemplate.REQUIRED);
              sceneTemplate.setPreference(HSceneTemplate.
                             SCENE_SCREEN_LOCATION,
                             new HScreenPoint((float)0,(float)0),
                             HSceneTemplate.REQUIRED);
              mScene = factory.getBestScene(sceneTemplate);
              mScene.requestFocus();
              mScene.addFocusListener(this);
    Then, I add the above container to the mscene as follows,
    mCurrentContainer = myContainer;
    mScene.add(mCurrentContainer); // Keys Presses do not work if left uncommented
    mScene.setVisible(true);
    mScene.requestFocus();
    mScene.addKeyListener( mCurrentContainer);
    mCurrentContainer.setVisible(true);
    mCurrentContainer.requestFocus();
    I see the buttons correctly and the "List" button is highlighted correctly. However, I do not get any key presses.
    Now, if I comment out "mScene.add()" as follows,
    mCurrentContainer = myContainer;
    // mScene.add(mCurrentContainer); // Now the key presses works correctly.
    mScene.setVisible(true);
    mScene.requestFocus();
    mScene.addKeyListener( mCurrentContainer);
    mCurrentContainer.setVisible(true);
    mCurrentContainer.requestFocus();
    The key presses works correctly. However, the buttons are not displayed now.
    What am I missing?
    Thanks!

    I have not tried the above suggestions but the problem is solved. The issue was - I had the requirement of creating a a default child record when the parent record is created. I was creating the child record using insert statement in Prepared Statement in the doDML of parent EOImpl. So it is not creating a row in the EO and when I add the second record through the application and save, the getRowCount returns 1 which is new record that created through application. Sorry for not providing this info earlier and Thank You all.
    Regards, Pradeep

  • Getting action event of table component inside java script function of anot

    Hello,
    <af:document id="d1" partialTriggers="pt1" theme="dark">
    <f:facet name="metaContainer">
    <af:resource type="javascript"> function handleTableDoubleClick(evt) {
    var table = evt.getSource(); AdfCustomEvent.queue(table, "TableDoubleClickEvent",{},true); evt.cancel();
    function handleRowSelectionClick(evt) {
    var component = evt.getSource();
    AdfCustomEvent.queue(component, "rowSelectionClickEvent",{},true);
    evt.cancel();
    function handleLinkSelection(linkClickEvent){
    var table=AdfPage.PAGE.findComponent("tbl");
    alert("Components:"+table);
    AdfActionEvent.queue(table,true);
    </af:resource>
    </f:facet>
    <af:form id="f1" usesUpload="true">
    <af:pageTemplate id="pt1" viewId="/ESOPM_Base_Template.jspx">
    <f:facet name="main_content">
    <af:panelStretchLayout id="pgl" bottomHeight="0px" inlineStyle="width:auto;">
    <f:facet name="center">
    <af:table varStatus="rowStat" width="auto" value="#{MainContentBean.collectionModel}"
    rows="#{MainContentBean.collectionModel.rowCount}" rowSelection="single" contentDelivery="immediate"
    var="row" rendered="true" id="tbl" >
    <af:clientListener method="handleTableDoubleClick" type="dblClick"/>
    <af:serverListener type="TableDoubleClickEvent" method="#{MainContentBean.HandleDoubleClickTable}"/>
    <af:clientListener method="handleRowSelectionClick" type="click"/>
    <af:serverListener type="rowSelectionClickEvent" method="#{MainContentBean.HandleRowSelection}"/>
    <af:forEach items="#{MainContentBean.columnNames}" var="name">
    <af:column sortable="true" headerText="#{name}" headerClass="TableHeader" sortProperty="#{name}"
    inlineStyle="width:100px;" id="c1">
    <af:panelGroupLayout id="pnl_grCol" halign="center" valign="middle">
    <af:image source="/images/folder.gif" rendered="#{name eq 'Collection Name'}" visible="#{row['Document Type'] eq ''}"
    id="i2"/>
    <af:image source="/images/Computer_File.gif" rendered="#{name eq 'Collection Name'}"
    visible="#{row['Document Type'] eq 'Document' or 'Application'}" id="i3"/>
    <af:outputText value="#{row[name]}" id="aot1" clientComponent="true" >
    <af:clientListener method="handleRowSelectionClick" type="click"/>
    <af:serverListener type="SelectionClickEvent" method="#{MainContentBean.HandleRowSelection}"/>
    </af:outputText>
    </af:panelGroupLayout>
    </af:column>
    </af:forEach>
    </af:table>
    this is my code , In this when i am clicking on rowSelectionEvent its going to bean class i want the same action to be performed on the click of outputText so what can i do for that ,I want to execute same action as performed on table component for single click , on outputText
    Regards
    Mayur Mitkari

    Hi,
    I think there are two solutions to the problem
    1. <af:outputText ... clientComponent="true"
    2. If this doesn't work, replace af:outputText with <af:inputText ... readOnly="true"/>
    Frank

  • How to catch key events

    Hello!
    I have a component which extends JPanel. Now I dynamically add a JTextField as a child to this component. The problem is: when the textfield has focus, how can I get key events in my panel before the textfield gets them (and maybe intercept them so that the textfield doesn't get them at all)?
    Background: the component is a self written table and the textfield is an editor. Now I have to make sure that when I am editing and press e.g. "cursor up", that not the textfield will get this key event but the table (which should traverse the current cell then ...)
    The problem is: I cannot change the textfield (extend it or something) because a possible solution has to work with any java awt "Component" (or at least with JComponent).
    Any help very appreciated.
    Michael

    Hello,
    implement the keyListener interface for the Extended component...
    and in Keypressed method
    keyPressed(keyEvent){
    // do all ur reuirements here
    //and comsume the keyEvent...
    hope this helps

  • How to catch cell lost focuse event of matrix

    Dear all
    can you tell me how to catch the cell lost fouc event of matrix.
    i want to check the value is entered the that cell, which is not greter than the extising value..
    thanks in advance......

    Hi
    For that you can use either validate or lost focus event
    Private Sub SBO_Application_ItemEvent(ByVal FormUID As String, ByRef pVal As SAPbouiCOM.ItemEvent, ByRef BubbleEvent As Boolean) Handles SBO_Application.ItemEvent
            ' BubbleEvent sets the behavior of SAP Business One.
            ' False means that the application will not continue processing this event.
            ' Validate event
            If (pVal.FormType = 133) And (pVal.ItemUID = 38) And (pVal.ColUID = 1) And _
              (pVal.EventType = SAPbouiCOM.BoEventTypes.et_VALIDATE) Then
                If (pVal.Before_Action) Then
                    'write your code
                End If
            End If
            'Lost focus event
            If (pVal.FormType = 133) And (pVal.ItemUID = 38) And (pVal.ColUID = 1) And _
             (pVal.EventType = SAPbouiCOM.BoEventTypes.et_LOST_FOCUS) Then
                If (pVal.Before_Action) Then
                    'write your code
                End If
            End If
        End Sub
    Hope this helps
    Regards
    Arun

  • How te get the event of SAVE button in WDDOPOSTPROCESSING method

    Hello,
    am using an application that was configured with FPM, and my question is  how can I get the event wehen the user click on the save button in the method WDDOPOSTPROCESSING?
    will explain again!
    if the user click on the save button, how can I know or get the event in the WDDOPOSTPROCESSING?
    am talking here about the general save button in the header..
    please let me know if somebody knows
    thank you all

    just to make it easy for me,  the save button has an ID , i dont know how to get that ID  or where that action will be generated , i dont know where to implement my method, and this is the problem i dont know where or which method or class or IF will be genareted
    the SAP Developper are taking this case into consideration , because normaly all the data will be stored first in a buffer table, and after the suer clicks on the SAVE button, all the data will bestored in the corresponding INFOTYPE using the CP of the person, but in case of some INFTYPEs that are specified with 'P' instead of 'CP' we can't use the SAP Standard methode insert_infty , and this is the reason why i believe that there must be an alternative way to save all DATA of all Subtable by clicking only once on the save button.
    I foundout that the methode WDDOPOSTPROCESSING will be generated after clicking on the SAVE button, but as I said, i can't get the corresponding event ????
    please is somebody has an Idea, am still interessted to get the solution.
    thank you all

  • Capturing the TAB key event.

    How can I capture the TAB key event?
    I am trying to use it within a JTextField to do a normal text tab operation.
    Thanks,
    D

    I want to map the Tab key to a jTextField so that when the user is editing inside the jTextField they can press the TAB key to tab over a predefined number of characters.
    Thanks,
    D

  • Parent processes a key event.

    How to transfer the processing of key event of focusable component to it's parent? For example how to make a frame having a key listener added and containing buttons, text boxes, etc. to process key events?

    I found a way
    getToolkit().addAWTEventListener(
    new AWTEventListener() {
    public void eventDispatched(AWTEvent e) {
    //MouseEvent me = (MouseEvent)e;
    switch(e.getID()) {
    case MouseEvent.MOUSE_RELEASED:
    System.out.println("released:id="+e.getID());break;
    case MouseEvent.MOUSE_PRESSED:
    System.out.println("pressed:id="+e.getID()); break;
    case MouseEvent.MOUSE_CLICKED:
    System.out.println("clicked:id="+e.getID());break;
    case MouseEvent.MOUSE_EXITED:
    System.out.println("exited:id="+e.getID());break;
    case MouseEvent.MOUSE_ENTERED:
    System.out.println("entered:id="+e.getID());break;
    case MouseEvent.MOUSE_DRAGGED:
    System.out.println("dragged:id="+e.getID());break;
    default:
    System.out.println("other");
    AWTEvent.MOUSE_EVENT_MASK
    getToolkit().addAWTEventListener(
    new AWTEventListener() {
    public void eventDispatched(AWTEvent e) {
    //MouseEvent me = (MouseEvent)e;
    switch(e.getID()) {
    case MouseEvent.MOUSE_DRAGGED:
    System.out.println("dragged:id="+e.getID());break;
    case MouseEvent.MOUSE_MOVED:
    System.out.println("moved:id="+e.getID());break;
    default:
    System.out.println("other");
    AWTEvent.MOUSE_MOTION_EVENT_MASK
    }

  • How to make a cell in a JTable to be uneditable and handle events

    I tried many things but failed,How do you make a cell in a JTable to be uneditable and also be able to handle events>Anyone who knows this please help.Thanx

    Hello Klaas2001
    You can add KeyListener ,MouseListener
    Suppose you have set the value of cell using setValueAt()
    table.addKeyListener(this);
    public void keyTyped(KeyEvent src)
    String val="";
    int r= table.getEditingRow();
    int c= table.getEditingColumn();
    val=table.getValueAt(r,c).toString();
    if (r!=-1 && c!=-1)
    TableCellEditor tableCellEditor = table.getCellEditor(r, c);
    tableCellEditor.stopCellEditing();
    table.clearSelection();
    table.setValueAt(val,r,c);
    public void keyReleased(KeyEvent src)
    public void keyPressed(KeyEvent src)
    table.addMouseListener(this);
    public void mouseClicked(MouseEvent e)
    public void mouseEntered(MouseEvent e)
    public void mouseExited(MouseEvent e)
    public void mousePressed(MouseEvent e)
    public void mouseReleased(MouseEvent e)
    if(e.getClickCount()>=2)//Double Click
    table.clearSelection();
    int r= table.getEditingRow();
    int c= table.getEditingColumn();
    if (r!=-1 && c!=-1)
    TableCellEditor tableCellEditor = table.getCellEditor (
    r,c);
    tableCellEditor.stopCellEditing();
    table.clearSelection();
    table.setValueAt("",r,c);
    }//Mouse Released
    You can remove keyListener and Mouse Listener whenever You want to edit
    then add it later.
    Regarding handling events implement javax.swing.event.TableModelListener
    table.getModel().addTableModelListener(this);
    public void tableChanged(javax.swing.event.TableModelEvent source)
    TableModel tabMod = (TableModel)source.getSource();
         switch (source.getType())
    case TableModelEvent.UPDATE:
         break;
         }//Table Changed Method
    //This method gets fired after table cell value is changed.

Maybe you are looking for

  • Display xero as zero and null as space in BEx excel reports - urgent

    How do I set query properties, where difference of 2 key figures is if zero will display zero. but if there is a key figure which has a null value (not assigned), then difference between 2 KFs will be space. Thanks Swati

  • Adding a Field in  search Criteria in Web UI

    Hello All ,    I am working on SAP CRM 7.0 Webui Marketing module (Business Role : Marketingpro) . Here when I select the "Account&Product" Work Center and go to search Contact . Here we will move to the Search Contact View here we will get a list bo

  • Skip the DELETE command on logical standby

    Hi All, I want to skip the DELETE command on logical standby. DB Version - 10.2 OS - Linux Primary DB and logical standby DB . In our DB schema some transaction tables. We delete data from those tables by delete commands. Delete command, also delete

  • JDK 1.6 Installation INSTALLDIR with white space

    Hi, I am trying to install jdk 1.6 in silent mode. I am using following command: <jdk1.6>.exe /s INSTALLDIR="C:\Program Files\CA\IAM\JDK1.6" But this shows me the usage dialog. When I remove INSTALLDIR then it gets installed in Program Files\Java. Wh

  • Produce a range of numbers with select from the gaps of ID column

    (1) Suppose I have a table t which has rows like this: A B 2 4 6 7 I would like to use select to produce rows with numbers ranging between A column and B column inclusive for each row, like this: select ... from t ... 2 3 4 6 7 (2) Suppose I have ID