Oracle Fusion Middleware Java API Reference for Oracle Extension SDK Reference
11g Release 1 (11.1.1)


Class TreeMouseAdapter

  extended by java.awt.event.MouseAdapter
      extended by oracle.jdeveloper.tree.TreeMouseAdapter
All Implemented Interfaces:
java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.awt.event.MouseWheelListener, java.util.EventListener

public class TreeMouseAdapter
extends java.awt.event.MouseAdapter

This class sifts through the mousePressed() and mouseReleased() events that are generated by a JTree. It is necessary to listen to these events instead of mouseClicked() because the mouseClicked() event is very particular. In order for a mouseClicked() event to be fired, the mouse must be pressed and released at the same POINT on the screen. If the mouse moves between the pressing and releasing of the button even by one pixel, the mouseClicked() event does not fire.

So what is done here is that the row that the mouse is pressed on is compared to the row where the mouse is released. If the rows are the same, then this is counted as a "click", and the appropriate action is taken. If the rows are different, then the user moved the mouse off of the original object during the click, and this probably means that the user does not want to click on the tree node after all.

However, in some circumstances, it is actually ok to count the mouse pressed-released pair as a click even if the mouse is released somewhere outside of the object where the mouse was pressed. This is acceptable if the time between the mousePressed() and mouseReleased() events is adequately short enough. Some usability labs call this the "bounce time" of the mouse click. So even if the mouse is moved out of the original object, if the duration of the click is less than the bounce time, it is counted as a click and the appropriate action is taken.

Constructor Summary
TreeMouseAdapter(javax.swing.JTree tree)
Method Summary
 void mousePressed(java.awt.event.MouseEvent e)
          Overrides MouseAdapter definition.
 void mouseReleased(java.awt.event.MouseEvent e)
          Overrides MouseAdapter definition.
Methods inherited from class java.awt.event.MouseAdapter
mouseClicked, mouseDragged, mouseEntered, mouseExited, mouseMoved, mouseWheelMoved
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Detail


public TreeMouseAdapter(javax.swing.JTree tree)
Constructor. Requires a reference to a JTree.

Method Detail


public void mousePressed(java.awt.event.MouseEvent e)
Overrides MouseAdapter definition. This records the time when the mousePressed() event occurred and what the corresponding row in the JTree is.

Specified by:
mousePressed in interface java.awt.event.MouseListener
mousePressed in class java.awt.event.MouseAdapter


public void mouseReleased(java.awt.event.MouseEvent e)
Overrides MouseAdapter definition. It follows these steps:
  1. If the row where the mouse was pressed is undefined, then reset the state of this instance and return.
  2. Else if the pressed row is the same as the released row, then take the appropriate action.
  3. Else if the difference in time between the mousePressed() and mouseReleased() is less than the BOUNCE_TIME, then accept this mouse action as a click and take the appropriate action.
  4. Else the mouse action is not to be interpreted as a mouse click.

Specified by:
mouseReleased in interface java.awt.event.MouseListener
mouseReleased in class java.awt.event.MouseAdapter

Oracle Fusion Middleware Java API Reference for Oracle Extension SDK Reference
11g Release 1 (11.1.1)


Copyright © 1997, 2010, Oracle. All rights reserved.