JDK-4587775 : JTree still reporting weird scrolling increments
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.4.0
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_2000
  • CPU: x86
  • Submitted: 2001-12-11
  • Updated: 2003-03-12
  • Resolved: 2003-03-12
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
5.0 tigerFixed
Related Reports
Relates :  
Description
Bug 4365758 is marked as integrated in Merlin, but mouse wheel scrolling still isn't correct for JTree.  This is easily reproducible using the Tree demo of SwingSet2.  There are a couple problems:

* By default, one click/rotation of the mouse wheel should scroll by three nodes, and shouldn't ever scroll so that a node is partially visible.  When repeatedly mouse scrolling down (or up) an expanded JTree, scrolling is often done by an incorrect amount.

* Mouse wheel scrolling down by one "click", and then up by one "click" should leave you exactly where you started, but it doesn't.  Starting from the top of the Tree demo, it takes _6_ iterations of wheel-down/wheel-up to get back to the very top of the tree, each wheel movement leaving you in a slightly different spot.

Correct wheel scrolling can be seen in the Table Demo, the List Demo (though not in the Prefixes and Suffixes boxes), and the ComboBox Demo.

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: tiger FIXED IN: tiger INTEGRATED IN: tiger tiger-b03
24-08-2004

EVALUATION Name: apR10133 Date: 04/29/2002 The problem is that the mouse wheel handler pass the scroll unit's amount to the scrollbar, but the last one doesn't compute the right increment/decrement value. Scrollbar actually takes the current JTree's getScrollableUnitIncrement() and multiply it on the scroll unit's amount (from the MouseWheelEvent). But this implementation has the following problems: - the tree's row may have a different height for different rows (as well as for JList)! - if the first visible row is only partially visible then the unit increment will be computed to make the next row to be the first. It means the scrollbar will multiply this "cuted" unit increment on the scroll units amount and the result will be totally wrong. I think we need a new method like Scrollable.getScrollableUnitIncrement() which will be able to take into account "scroll units amount". I think we need a new interface Scrollable2 with the appropriate method to provide the mouse wheel support: public int getScrollableUnitIncrement(Rectangle visibleRect, int orientation, int direction int unitsAmount) Parameters: visibleRect - The view area visible within the viewport orientation - Either SwingConstants.VERTICAL or SwingConstants.HORIZONTAL. direction - Less than zero to scroll up/left, greater than zero for down/right. unitsAmount - the fixed amount of units to be scrolled. Returns: The increment for scrolling in the specified direction. This value should always be positive. ###@###.### ====================================================================== Name: apR10133 Date: 05/31/2002 To avoid the API change we could take a getUnitIncrement() and set the value (by calling setValue()) n times where n is a number of units from MouseWheelEvent. Unfortunately it will cause the udesirable animation effect. ###@###.### ======================================================================
24-08-2004

WORK AROUND
24-08-2004

SUGGESTED FIX Name: apR10133 Date: 05/31/2002 ------- BasicScrollBarUI.java ------- *** /tmp/sccs.fkayMC Wed May 8 19:44:36 2002 --- BasicScrollBarUI.java Wed May 8 16:27:22 2002 *************** *** 808,833 **** int units) { // This method is called from BasicScrollPaneUI to implement wheel // scrolling, as well as from scrollByUnit(). ! int delta = units; ! if (direction > 0) { ! delta *= scrollbar.getUnitIncrement(direction); ! } ! else { ! delta *= -scrollbar.getUnitIncrement(direction); ! } ! int oldValue = scrollbar.getValue(); ! int newValue = oldValue + delta; ! ! // Check for overflow. ! if (delta > 0 && newValue < oldValue) { ! newValue = scrollbar.getMaximum(); ! } ! else if (delta < 0 && newValue > oldValue) { ! newValue = scrollbar.getMinimum(); ! } ! scrollbar.setValue(newValue); } protected void scrollByUnit(int direction) { --- 808,838 ---- int units) { // This method is called from BasicScrollPaneUI to implement wheel // scrolling, as well as from scrollByUnit(). ! int delta; ! for (int i=0; i<units; i++) { ! if (direction > 0) { ! delta = scrollbar.getUnitIncrement(direction); ! } ! else { ! delta = -scrollbar.getUnitIncrement(direction); ! } ! int oldValue = scrollbar.getValue(); ! int newValue = oldValue + delta; ! ! // Check for overflow. ! if (delta > 0 && newValue < oldValue) { ! newValue = scrollbar.getMaximum(); ! } ! else if (delta < 0 && newValue > oldValue) { ! newValue = scrollbar.getMinimum(); ! } ! if (oldValue == newValue) { ! break; ! } ! scrollbar.setValue(newValue); ! } } protected void scrollByUnit(int direction) { ###@###.### ======================================================================
24-08-2004

PUBLIC COMMENTS
24-08-2004