oracle.jdeveloper.tree
Class TreeMouseAdapter
java.lang.Object
java.awt.event.MouseAdapter
oracle.jdeveloper.tree.TreeMouseAdapter
- All Implemented Interfaces:
- java.util.EventListener, java.awt.event.MouseListener
- 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.
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, mouseEntered, mouseExited |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
TreeMouseAdapter
public TreeMouseAdapter(javax.swing.JTree tree)
- Constructor. Requires a reference to a JTree.
mousePressed
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.
mouseReleased
public void mouseReleased(java.awt.event.MouseEvent e)
- Overrides MouseAdapter definition. It follows these steps:
- If the row where the mouse was pressed is undefined, then reset the state of this instance and return.
- Else if the pressed row is the same as the released row, then take the appropriate action.
- 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.
- Else the mouse action is not to be interpreted as a mouse click.
Copyright © 1997, 2004, Oracle. All rights reserved.