Bug 487039 - StyledText with auto scroll does not redraw scollbars correctly
Summary: StyledText with auto scroll does not redraw scollbars correctly
Status: NEW
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 4.5.1   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Platform-SWT-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords: helpwanted
Depends on:
Blocks:
 
Reported: 2016-02-02 13:28 EST by Rüdiger Herrmann CLA
Modified: 2020-05-19 09:39 EDT (History)
3 users (show)

See Also:


Attachments
Screenshot (24.88 KB, image/png)
2016-02-02 13:28 EST, Rüdiger Herrmann CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Rüdiger Herrmann CLA 2016-02-02 13:28:14 EST
Created attachment 259497 [details]
Screenshot

I use a StyledText that is 'configured' to automatically show or hide scrollbars as necessary. A Resize and a Modify listener is used to show/hide the scrollbars.

When the StyledText is shown for the first time the area in which usually the vertical scrollbar is located in appears black (see the attached screenshot).

The problem can be reproduced with this snippet:

public class StyledTextAutoScrollBug {

  public static void main( String[] args ) {
    Display display = new Display();
    Shell shell = new Shell( display );
    shell.setLayout( new FillLayout() );
    int style = SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL;
    StyledText textWidget = new StyledText( shell, style );
  
    new TextFieldAutoScrollBar( textWidget ).install();
    
    shell.setSize( 300, 250 );
    shell.open();
    while( !shell.isDisposed() ) {
      if( !display.readAndDispatch() ) {
        display.sleep();
      }
    }
    display.dispose();
  }
  
  static class TextFieldAutoScrollBar {
    private final StyledText text;

    TextFieldAutoScrollBar( StyledText text ) {
      this.text = text;
    }

    void install() {
      Listener scrollBarListener = new ScrollBarListener();
      text.addListener( SWT.Resize, scrollBarListener );
      text.addListener( SWT.Modify, scrollBarListener );
      updateScrollBars();
//      relayout();
    }

    private void updateScrollBars() {
      Rectangle trim = computeTrim();
      Point size = computeSize();
      text.getHorizontalBar().setVisible( trim.width <= size.x );
      text.getVerticalBar().setVisible( trim.height <= size.y );
    }

    private void relayout() {
      text.getParent().layout( true );
    }

    private Rectangle computeTrim() {
      Rectangle clientArea = text.getClientArea();
      return text.computeTrim( clientArea.x, clientArea.y, clientArea.width, clientArea.height );
    }

    private Point computeSize() {
      return text.computeSize( SWT.DEFAULT, SWT.DEFAULT, true );
    }

    private class ScrollBarListener implements Listener {
      @Override
      public void handleEvent( Event event ) {
        text.getParent().setRedraw( false );
        try {
          updateScrollBars();
          if( event.type == SWT.Modify ) {
            relayout();
            text.showSelection();
          }
        } finally {
          text.getParent().setRedraw( true );
        }
      }
    }
  }

}


If a re-layout of the parent is enforced like this
  styldText.getParent().layout( true );
the problem disappears. In the snippet above, disable/enable the call to layout() in install() .