<Swing Dev> [10] RFR JDK-7190581: Nimbus: PgDn at the bottom causes scrolling
Prasanta Sadhukhan
prasanta.sadhukhan at oracle.com
Wed Jul 26 06:52:00 UTC 2017
Hi All,
Please review a fix for an issue where it is seen that pressing "Page
down" after "ctrl-END" in TextArea causes extra scroll down for Nimbus L&F.
ctrl-END is supposed to go the very end of the document and show the
caret at the end, so any "page down" should not cause any further scroll
down.
This was happening because JTextArea uses
DefaultEditorKit.VerticalPageAction() to execute pagedown/up and
due to container layout a bit different in different l&fs, in
ViewportLayout.layoutContainer causes "viewSize" to be different as set
in vp.setViewSize(viewSize);
So, the "initialY" view point as obtained from
VerticalPageAction#target.getVisibleRect(); is different in Nimbus l&f
as compared to say, Metal l&f.
When constrainY() is called to ascertain if "initialY" is valid, it
calculates new Y again [using Math.max(0, target.getHeight() - vis);]
which causes "newVis.y" to be different so
target.scrollRectToVisible(newVis); at the end with new visual y ,
causes scrolling.
In other l&f like metal, initialY and newVis.y are same so no additional
scrolling is seen.
Proposed fix is to ensure if caret position [obtained from
target.getCaretPosition()] is same as visible offset,
which means caret is at the end of the document when "page down" is
pressed after ctrl-END
or
at the start when "page up" is pressed after ctrl-HOME
then correct the newVis.y to prevent additional scrolling.
Bug: https://bugs.openjdk.java.net/browse/JDK-7190581
webrev: http://cr.openjdk.java.net/~psadhukhan/7190581/webrev.00/
I have tested with Notepad demo which uses DefaultEditorKit with
pageup/down actions and also other regression tests which uses
DefaultEditorKit.
Regards
Prasanta
More information about the swing-dev
mailing list