Mouse release event on jtable if its pressed outside jtable

Is there any way to to catch the mouse release event on JTABLE if the mouse has been pressed on any other window.
If Its pressed on jtable it can catch mouse release but if if its pressed out side than no mouse event is generated like mouse move and release if I drag mouse over jtable
I have used mouse motion as well as click listeners but to no avail.
Thanx in advance

>
You could create a generic listener to add to all
components (or possibly an event queue or something)
to get all mouse release events and refire the event
to the component the mouse is really over.One way to do this would be the following:
    AWTEventListener globalMouseListener = new AWTEventListener() {
        public void eventDispatched(AWTEvent event) {
            MouseEvent me = (MouseEvent)event;
            if( me.getID() == MouseEvent.MOUSE_RELEASED ) {
                System.out.println("Mouse relased at: " + me.getPoint());
                System.out.println("Source: " + me.getSource());
    Toolkit.getDefaultToolkit().addAWTEventListener(
            globalMouseListener, AWTEvent.MOUSE_EVENT_MASK);Now, the source of the MouseReleased event will be the component on which the mouse was pressed, but once you have the coordinates you can probably transform them and find out if the mouse was released over your table using one or more of the SwingUtilities.convertPoint methods.
On the other hand, maybe there is a far simpler way of doing it than this...

Similar Messages

  • Mouse released event for scrollbar

    Hello,
    I have a java.awt.Scrollbar component on applet.
    I need to perform actions when user releases the mouse from the
    scrollbar. For example the user presses the mouse on the scrollbars
    tracking rectangle and starts to track. Then the values of the
    scrollbar changes and finally user releases the mouse left button-
    this final event (mouse release) is in my interest. How can i get
    mouse release event from scrollbar? The AdjustmentListener does not
    suit for me because it fires AdjustmentEvents even then when the user
    hasn't released the mouse. I need to perform more actions for every
    scrollbar's change; so my applet i slow at the moment, because every
    "tracking in scrollbar" creates a lot of events before the mouse is
    finally released.
    I added a MouseListener for my scrollbar, but mouseReleased event does
    not work. Can yo help me?
    Thank you, any help would be nice.
    Here is some demo code i tried:
    import java.applet.Applet;
    import java.awt.*;
    import java.awt.event.*;
    public class Kerimisriba1 extends Applet implements
    AdjustmentListener, MouseListener{
         Scrollbar kerimisriba=new Scrollbar(Scrollbar.VERTICAL, 20, 5, 1,
    100); //algv��rtus, nupu suurus, v�him ja suurim v��rtus
         TextField tf=new TextField(10);
         public Kerimisriba1(){
              setLayout(new BorderLayout());
              add(kerimisriba, BorderLayout.WEST);
              add(tf, BorderLayout.SOUTH);
              //kerimisriba.addAdjustmentListener(this);
              kerimisriba.addMouseListener(this);
              System.out.println("AdjustmentEvent.TRACK="+AdjustmentEvent.TRACK);
         public void adjustmentValueChanged(AdjustmentEvent e){
              //System.out.println(e.getAdjustmentType());
              // tf.setText(kerimisriba.getValue()+"");
         public void mouseReleased(MouseEvent me){
              tf.setText("mouseReleased");
         public void mouseClicked(MouseEvent me){}      
         public void mouseEntered(MouseEvent me){}
         public void mouseExited(MouseEvent me){}
         public void mousePressed(MouseEvent me){}
    }

    I made a screenshot of how the applet works in my computer:
    http://charles.pri.ee/scroll.gif
    As you see in the java console,
    the statement System.out.println("mouseReleased");
    does not executes,
    in my computer.
    I tried this on co-workers comuter with Internet Explorer- there was no mouse release event either.
    I hope i'm not very annoying, but i still need help:)
    I replaced the constructor with init() method:
    import java.applet.Applet;
    import java.awt.*;
    import java.awt.event.*;
    public class Kerimisriba1 extends Applet implements AdjustmentListener, MouseListener{
         Scrollbar kerimisriba=new Scrollbar(Scrollbar.VERTICAL, 20, 5, 1, 100); //algv��rtus, nupu suurus, v�him ja suurim v��rtus
         TextField tf=new TextField(10);
         public void init(){
              kerimisriba.addAdjustmentListener(this);
              setLayout(new BorderLayout());
              kerimisriba.addMouseListener(this);
              add(kerimisriba, BorderLayout.WEST);
              add(tf, BorderLayout.SOUTH);          
              System.out.println("AdjustmentEvent.TRACK="+AdjustmentEvent.TRACK);
         public void adjustmentValueChanged(AdjustmentEvent e){
              System.out.println(e.getAdjustmentType());
              tf.setText(kerimisriba.getValue()+"");
         public void mouseReleased(MouseEvent me){
              tf.setText("mouseReleased");
              System.out.println("mouseReleased");
         public void mouseClicked(MouseEvent me){
              System.out.println("mouseClicked");
         public void mouseEntered(MouseEvent me){}
         public void mouseExited(MouseEvent me){}
         public void mousePressed(MouseEvent me){
              System.out.println("mousePressed");

  • How to detect a mouse release event?

    AE SDK provides events for mouse click and mouse drag over effect plugin custom UIs, however there does not seem to be events for mouse release events.
    Are we supposed to keep ourselves an internal track of the mouse status? In that case, do we need to use OS-specific functions? Or is there a more clever way to do it?

    @shachar
    Yes, I set send_drag during the DoClick event callback, like they do in the SDK samples.
    Anyway, for the time being I found that using OS-specific functions (for example GetAsyncKeyState for Windows) does the job.

  • How can i implement a mouse listener event on jtable cell?

    I create JTable using a resultset,at the end of each row i add an image using JLabel(set imageicon of the JLabel).
    i want to track the event when user click on that image.
    What can i do for that?.
    I tried by implementing mouseListener interface for the JLabel but it's not working properly.

    Hi,
    Add MouseListener to the JTable.
    when the user clicks on the table use the method
    getValueAt( int selectedRow,int selectedColumn) to get the contents.
    Object obj = getValueAt( int selectedRow,int selectedColumn) .
    (If obj instance of JLabel)
    do your functionality.
    Hope this helps
    Cheers :)
    Nagaraj

  • Simulating mouse drag events?

    Hi all,
    I am wrinting unit tests for my swing application. For one test I want to simulate a drag event over a panel. I have tried JFCUnit, but does not seem to work for this, so I am trying to write my own.
    I create 3 mouse events and post them on the system event queue. A mouse press event, a mouse drag event and a mouse release event. MouseEvent's do let you specify a drag start and a drag end point in their constructor. So I have tried using both, but neither works.
    Am I doing anything wrong? The component I'm operating on gets the mouse pressed and mouse released events, but thats all.
    any help much appreciated,
    Justin

    I tried using the Robot class alright, but it does really wierd things. I sometimes doesn't work for simulating dragging events. I have a component that you can drag anywhere on the screen using the mouse, without having to use the titlebar. I am trying to test this dragging, but with the robot class, it looks like it goes into an infinate recursion. The mouseDragged method gets executed thosands of times, and you can see the panel shifting from its origional position to the new position and back again for a few seconds. Could be a bug in Robot class.

  • How can I get mouse pressed and mouse released positions on the desktop whi

    Hello All,
    I am generating a Frame using Swing API. My requirement is I need to capture the mouse pressed and mouse released positions, whenever user drags the mouse on desktop region (i.e. outside of the Frame). I require these points to find the rectangle region user has generated starting from mouse pressed to mouse released position. I need to pass that rectangle to Robot class in order to capture that desktop region.
    Can anybody help me out how can I achieve this using java on MAC, Linux and Windows platforms?
    Thanks in advance.
    Regards,
    VPKVL

    VPKVL wrote:
    DarrylBurke wrote:
    Can't be done in Java.I don't think that there is something which can't be done using java. When searched over net, found few applications which are using java for implementing this feature but not free, asking for license fee. I checked by downloading the demo version.
    Just want to know the hint how it can be achieved so that I can move further on that lines.
    Your thoughts ?They use JNI with the OS API.

  • JWindow blocking mouse wheel event?

    I have created a custom JPanel that acts as a container for another custom component that needs to receive mouse wheel events. When I place the custom JPanel in a JWindow the mouse wheel events do not get invoked, all though other mouse events work just fine. If I place the JPanel in a JFrame the mouse wheel events are invoked just fine (along with other mouse events).
    To keep things simple the JPanel handles the mouse listeners. Any idea why it would work when in a JFrame but not a JWindow?
    Edited by: skip1899 on Sep 21, 2009 7:20 AM

    The below sample code exhibits the behavior I am talking about on my system (1.6.0_16 on XP). Does it work for you? Is there something I am missing?
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseListener;
    import java.awt.event.MouseWheelEvent;
    import java.awt.event.MouseWheelListener;
    import javax.swing.JFrame;
    import javax.swing.JWindow;
    public class TestWindow extends JWindow implements
       MouseWheelListener,MouseListener {
         public TestWindow() {
              setSize(200,200);
              addMouseWheelListener(this);
              addMouseListener(this);
      public static void main(String args[]) {
           JFrame  frame = new JFrame();
           frame.setSize(300,300);
           frame.setVisible(true);
           TestWindow win = new TestWindow();
           win.setVisible(true);
    public void mouseWheelMoved(MouseWheelEvent e) {
         System.out.println("Mouse Wheel Moved!");
    public void mouseClicked(MouseEvent arg0) {
         System.out.println("Mouse Clicked!");
    public void mouseEntered(MouseEvent arg0) {
         System.out.println("Mouse Entered!");
    public void mouseExited(MouseEvent arg0) {
         System.out.println("Mouse Exited!");     
    public void mousePressed(MouseEvent arg0) {
         System.out.println("Mouse Pressed!");     
    public void mouseReleased(MouseEvent arg0) {
         System.out.println("Mouse Release!");
     

  • Actionscript 3 / Firefox / Mouse release outside stage

    So I need to be able to detect when the user releases the
    mouse button outside the stage/movie bounds. I am using
    Actionscript 3 / Flash 9.
    Since onReleaseOutside was nixed, and setCapture is no longer
    there now that Flash 9 is final, I'm using an event listener for
    mouse_up on the stage. This works sometimes... but specifically not
    when running inside Firefox 2.0 on a Mac..or when wmode is set to
    something non standard (opaque or transparent running on
    Windows/Firefox).
    This is quite critical actually, pretty easy to repro,
    assuming you have Firefox and MAC. Just drag a slider component
    onto your stage inside a test app. Publish, then run inside the
    browser. If you drag the slider, mouse outside the movie bounds,
    then release..then mouse back over movie, the slider continues to
    animate - thinking you still have the mouse pressed.
    I've also tried inspecting the buttonDown property of the
    mouse move event..but once you've released outside the bounds of
    the movie - it's always true.
    More info at
    http://www.justsuppose.com
    I'm grasping for straws..anyone stumble across a
    workaround???
    Thanks,
    Corey

    UPDATE: Stumbled upon a workaround after much trial and
    error. At least until they fix mouse_up.
    So considering the mouseLeave event... This event is
    dispatched usually as soon as your cursor leaves the bounds of the
    player window. But... if you've moused down first, then dragged
    outside window, the mouseLeave is not fired *until* Flash is done
    tracking. In other words, until the user lets go of the mouse
    button.
    So now I listen for *both* mouse up and mouseLeave on the
    stage object and I can reliably (cross browser), detect when the
    user has released the mouse button in the case the cursor is
    outside of the stage. In this scenario I only attach the mouseLeave
    and mouseUp listeners on the stage after the user has first moused
    down. I then remove them once I've detected the mouse up.
    Still hoping for a fix, but at least this provides an
    alternative (albeit sneaky) work around.

  • JTree select on mouse release

    How can I force a JTree to change selection on a mouse release rather than the mouse press?
    Background - I have a component that uses a JTree as a navigation device - click on a node in the tree and the right side of the GUI shows a particular panel. Some panels allow user to drag a node from the navigation tree into the panel on the right side. The drag and drop is working fine, except that when a node in the tree is clicked, it changes which panel is showing and the place that I wanted to drag to is no longer visible.
    I've temporarily worked around it by adding a "locked" checkbox to the navigation tree, so that if the checkbox is locked then I just set the tree selection back to what it was when the selection changes. This is not very user friendly. Ideally, I'd like the selection in the tree to change only when the mouse is released. Alternately, I could live with only starting a drag when the CTRL key was pressed or something similar.

    mclabo01 wrote:
    How can I force a JTree to change selection on a mouse release rather than the mouse press?This is what I might try:
    -- use getMouseListeners to save the array of MouseListener[] to an instance field
    -- iterate over the array and removeMouseListener all of them
    -- add a single MouseListener
    ---- in mouseReleased, construct a new MouseEvent from the ME received as parameter, changing the ID from MOUSE_RELEASED to MOUSE_PRESSED
    ---- iterate over the array and invoke mousePressed on each listener with the constructed event
    May work, may not. And you may have to collect the MouseListeners after the tree is made visible.
    db
    edit It appears there's no need to modify the MouseEvent. Proof of concept (may need some tuning for different treatment of each mouse button):import java.awt.event.*;
    import javax.swing.*;
    public class MouseReleaseSelectTree {
      MouseListener[] listeners;
      public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
          @Override
          public void run() {
            new MouseReleaseSelectTree().makeUI();
      public void makeUI() {
        JTree tree = new JTree();
        listeners = tree.getMouseListeners();
        for (MouseListener listener : listeners) {
          tree.removeMouseListener(listener);
        tree.addMouseListener(new MouseAdapter() {
          @Override
          public void mouseClicked(MouseEvent e) {
            for (MouseListener listener : listeners) {
              listener.mouseClicked(e);
          @Override
          public void mousePressed(MouseEvent e) {
          @Override
          public void mouseReleased(MouseEvent e) {
            for (MouseListener listener : listeners) {
              listener.mousePressed(e);//pressed);
          @Override
          public void mouseEntered(MouseEvent e) {
            for (MouseListener listener : listeners) {
              listener.mouseEntered(e);
          @Override
          public void mouseExited(MouseEvent e) {
            for (MouseListener listener : listeners) {
              listener.mouseExited(e);
        JFrame frame = new JFrame();
        frame.add(new JScrollPane(tree));
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(400, 400);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    }Edited by: DarrylBurke

  • How i  add keyrealease event in jtable

    i am working with jtable. now i want to change more than two different cell value.it will work with key release event not mouse listner event. i cant do this using key realese.
    pls help me.
    thanks in advance.

    pls help me. To get a better and quick help, depends on you clarity and good explanation of the problem. You have the problem which means you try to sort it out; as a result, you need to give more explanations so that you can get quick and better help.
    Regards,
    Alan Mehio
    London,UK

  • Image control mouse move event updates

    I would like to drag the ROI around in the Image control (holding down the left mouse button) and continually read out the ROI coordinates. I can't find a way to do this: the mouse move event does not seem to fire if I hold the left mouse button down. I assumed that I would have
    1. Mouse down when I click and hold.
    2. Mouse move when I move the ROI around.
    3. Mouse up when I release the left mouse button.
    This does not seem to be the case.
    I've done a simple workaround which is
    1. Use the key up event to check that the space bar has been pressed.
    2. Use this to toggle a "lock" boolean which locks the target to the mouse coordinates.
    3. Use the mouse move event to return the Image Control Mouse Coordinates property.
    4. Unlcok the target from the mouse coordinates by pressing the space bar again.
    This kind of works, but it is much less intuitive than the standard windows "click and drag".
    Any comments appreciated.
    Thanks.
    PS The Image Control is excellent, it has saved me lots of development time. Also, the ROI tools are hugely useful.

    If you filter the mouse down event (MOUSE DOWN?) then the coordinated are always returned on mouse move event weather the mouse is down or not.  I did get the coordinates when the left button was down anyway it was just when the right button was down which the move event was not handled (due to the popup menu consuming the event first?)  I thing there is a good way to do this with dynamic event registration, and NI has a similar example of drag and drop of controls, but I am not at my LV machine to look for it right now.  If I am wrong I am sorry it is early and my coffee is not brewed yet.
    Paul
    Paul Falkenstein
    Coleman Technologies Inc.
    CLA, CPI, AIA-Vision
    Labview 4.0- 2013, RT, Vision, FPGA

  • Mouse dragged event - problem(logic problem?)

    Hi! I have a window which is started by a frame. At the moment I have a Mouse Dragged event. The ideea is that I would like to drag the window to various parts of the screen but as it is the window flickers a lot and it keeps on jumping to various locations when dragging it. Is there a way to redraw and move the window only once the mouse button was released from the drag and not all the time?!
    Thank you.

    if i understood your question correct setVisible(false) when you grab it setVisivble(true) when you release it. If you want it to be still shown in the ori�ginal place while dragging make a second window that stays at the starting location and id removed after the first diappears.
    An even better solution would be to remember the location of the mouse in a pousepressed event and then wait for mousereleased. (and set a boolean true if the mouse pressed was inside the window).

  • How can I (neatly) control mouse click events in a multi-dimensional array?

    Hello everyone!
         I have a question regarding the use of mouse clicks events in a multi-dimensional array (or a "2D" array as we refer to them in Java and C++).
    Background
         I have an array of objects each with a corresponding mouse click event. Each object is stored at a location ranging from [0][0] to [5][8] (hence a 9 x 6 grid) and has the specific column and row number associated with it as well (i.e. tile [2][4] has a row number of 2 and a column number of 4, even though it is on the third row, fifth column). Upon each mouse click, the tile that is selected is stored in a temporary array. The array is cleared if a tile is clicked that does not share a column or row value equal to, minus or plus 1 with the currently targeted tile (i.e. clicking tile [1][1] will clear the array if there aren't any tiles stored that have the row/column number
    [0][0], [0][1], [0][2],
    [1][0], [1][1], [1][2],
    [2][0], [2][1], [2][2]
    or any contiguous column/row with another tile stored in the array, meaning that the newly clicked tile only needs to be sharing a border with one of the tiles in the temp array but not necessarily with the last tile stored).
    Question
         What is a clean, tidy way of programming this in AS3? Here are a couple portions of my code (although the mouse click event isn't finished/working correctly):
      public function tileClick(e:MouseEvent):void
       var tile:Object = e.currentTarget;
       tileSelect.push(uint(tile.currentFrameLabel));
       selectArr.push(tile);
       if (tile.select.visible == false)
        tile.select.visible = true;
       else
        tile.select.visible = false;
       for (var i:uint = 0; i < selectArr.length; i++)
        if ((tile.rowN == selectArr[i].rowN - 1) ||
         (tile.rowN == selectArr[i].rowN) ||
         (tile.rowN == selectArr[i].rowN + 1))
         if ((tile.colN == selectArr[i].colN - 1) ||
         (tile.colN == selectArr[i].colN) ||
         (tile.colN == selectArr[i].colN + 1))
          trace("jackpot!" + i);
        else
         for (var ii:uint = 0; ii < 1; ii++)
          for (var iii:uint = 0; iii < selectArr.length; iii++)
           selectArr[iii].select.visible = false;
          selectArr = [];
          trace("Err!");

    Andrei1,
         So are you saying that if I, rather than assigning a uint to the column and row number for each tile, just assigned a string to each one in the form "#_#" then I could actually just assign the "adjacent" array directly to it instead of using a generic object to hold those values? In this case, my click event would simply check the indexes, one at a time, of all tiles currently stored in my "selectArr" array against the column/row string in the currently selected tile. Am I correct so far? If I am then let's say that "selectArr" is currently holding five tile coordinates (the user has clicked on five adjacent tiles thus far) and a sixth one is being evaluated now:
    Current "selectArr" values:
           1_0
           1_1, 2_1, 3_1
                  2_2
    New tile clicked:
           1_0
           1_1, 2_1, 3_1
                  2_2
                  2_3
    Coordinate search:
           1_-1
    0_0, 1_0, 2_0, 3_0
    0_1, 1_1, 2_1, 3_1, 4_1
           1_2, 2_2, 3_2
                  2_3
         Essentially what is happening here is that the new tile is checking all four coordinates/indexes belonging to each of the five tiles stored in the "selectArr" array as it tries to find a match for one of its own (which it does for the tile at coordinate 2_2). Thus the new tile at coordinate 2_3 would be marked as valid and added to the "selectArr" array as we wait for the next tile to be clicked and validated. Is this correct?

  • Mouse down event reading a string terminal trick

    Hi,
    I wondered why I was getting frustrated entering a pasword that was verified in the mouse down event of the OK button. This is becuase when you click the OK button the entered text is still in the buffer and not copied to the terminal. (Which is more natural than clicking somewhere on the FP first). Note pressing enter or tab gets the string control out of enter text mode.
    Turns out need update value while typing turned on if you want to gaurantee a correct read of a text input control in a mouse down event. As this is one of those not obvious but sometimes happens bugs... I have posted for reference for others :-)
    Example attached v8.6.1.
    Attachments:
    TestMouseDownEvent.vi ‏13 KB

    Nick wrote:
    Turns out need update value while typing turned on if you want to gaurantee a correct read of a text input control in a mouse down event.
    AFAIK, "Update value while typing" will trigger only a Value Change event of the Str Ctl.
    Mouse Down event will preceed a Value Change event, if you have both the event cases configured in your code.
    - Partha
    LabVIEW - Wires that catch bugs!

  • SAVE AS BUTTON WITH JAVA SCRIPT FOR MOUSE UP EVENT

    Please any one help with complete code for "SAVE AS" button to auto save the acrobat form in a user specified path
    with unique name or incremental name.Please post only full script for MOUSE UP event.

    Thanks George but i need an example.my actual need is
    i have created a SAVE INVOICE button.i have set the action"Mouse up" to run a Java script.
    Now i need a scriprt for the same.
    If i press that SAVE INVOICE button.the fie should save on "C:\Users\MUNNA\Desktop" automatically
    with unique name and the name should not remain same for next Save.because it overwrites the previous
    file so please post an example pdf with same.

Maybe you are looking for