JDK-7107099 : JScrollBar does not show up even if there are enough lebgth of textstring in textField
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 7
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2011-11-01
  • Updated: 2013-09-12
  • Resolved: 2012-03-06
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 Availabitlity Release.

To download the current JDK release, click here.
Other JDK 6 JDK 7 JDK 8
5.0-poolResolved 6u34Resolved 7u4Resolved 8 b29Fixed
Related Reports
Relates :  
Description
When text filed is re-freshed, JScrollBar does not show up even if there are enough lebgth of textstring in textField

CONFIGURATION:
JDK: 7/6u26/5u30

REPRODUCE:
1. Compile and invoke the attached test cae(Test.java)
2. Click the button "change text"

EXPECTED: 
attached "good.jpg"

ACTUAL:
attahched "bad.jpg"(ScrollBar does not show up)

FREQUENCT : 
This always occurs.

Comments
EVALUATION Before evaluation there is need to know a couple details of JScrollPane implementation: 1. ScrollBar visibility are set in ScrollPaneLayout#layoutContainer. That method is invoked after invalidate is invoked, therefore the layoutContainer method isn't invoked directly but postponed like invokeLater does. 2. ScrollBar values are set in the BasicScrollPaneUI#syncScrollPaneWithViewport method. That method is invoked from JViewport#fireStateChanged and can be invoked from the ScrollPaneLayout#layoutContainer method if viewport.bounds are changed, for example. Below are four lines of code from the attached Test.java that shows the problem with comments: textarea.setText(null); /* BasicScrollPaneUI#syncScrollPaneWithViewport will be invoked and scrollbars will be initialized for empty text. Note: scrollbars visibility is not corrected yet, but postponed by invalidate */ pane.setViewportView(textarea); /* Set new text and postpone JScrollBar invalidation. Note: syncScrollPaneWithViewport is not invoked here, but can be invoked later by ScrollPaneLayout#layoutContainer while invalidation (if needed) */ textarea.setText("after###1###\nafter###1###\nafter###1###\nafter###1###\nafter###1###\n"); /* Restore caret position, so JScrollPane will stay at the same view position */ textarea.setCaretPosition(0); After that code while ScrollPaneLayout#layoutContainer it looks for JScrollPane that there is no need to synchronize scrollbars, because view size and position remain the same as in last layout. Suggestion: I'm suggesting to force BasicScrollPaneUI#syncScrollPaneWithViewport invocation while first layout after viewports view is changed. This fix looks small and safe.
2012-02-21

EVALUATION This may be related to #5023525
2011-12-16