Microsoft KB Archive/238830

= PRB: Scroll Box Jumps Up and Down in UIColumnViewer Class Object =

Article ID: 238830

Article Last Modified on 6/14/2006

-

APPLIES TO


 * Microsoft Software Development Kit for Application Foundation Classes 1.0
 * Microsoft Software Development Kit for Java 3.2

-



This article was previously published under Q238830



SYMPTOMS
When you use the scroll box (thumb) to position the window contents while you are updating a UIColumnViewer class object, the thumb may jump up and down, which makes it difficult to see the contents of the window.



RESOLUTION
To work around this problem, follow these steps:
 * 1) In the startRefresh method, comment the line of code with the call to create the update thread. For details, see the steps in the "More Information" section.
 * 2) Compile, and then run the application.



Steps to Reproduce the Behavior
  Create a new program named TestViewer.java. This program creates a Frame with a table that contains five columns and one hundred rows. Because the data exceeds the size of the frame window, the program creates a scroll bar so that you can position the contents for viewing. Additionally, the program creates a timer thread to update the contents of the rows every three seconds.

In TestViewer.java, paste the following code: import java.awt.*; import com.ms.ui.*;

public class TestViewer {  private static TestFrame tframe = null; public static void main(String args[]) {     tframe = new TestFrame; tframe.initialize; }       } class TestFrame extends UIFrame {  private UIList         list         = null; private UpdateThread  updateThread = null; private int           iColumns     = 5; private int           iRows        = 100; private UIColumnViewer viewer      = null; private boolean       bToggle      = true;

public TestFrame {     super("UIColumnViewer Scroll Bar update test"); }  public void initialize {                 UIColumnHeader[] hdrs = new UIColumnHeader[] {        new UIColumnHeader("Col 1"), new UIColumnHeader("Col 2"), new UIColumnHeader("Col 3"), new UIColumnHeader("Col 4"), new UIColumnHeader("Col 5") };

setSize(600, 400); list = new UIList; viewer = new UIColumnViewer(hdrs, list); viewer.setWidths( (600/iColumns)-7 );

UIPanel panel = new UIPanel; panel.setLayout(new UIBorderLayout); panel.add(viewer, "center"); add(panel); show; refresh; startRefresh; }  private void startRefresh {     // WORKAROUND // Comment out this line to apply workaround. updateThread = new UpdateThread(this); }  public void refresh {      while (list.getChildCount > 0) list.remove(0);

viewer.paint(this.getGraphics); for (int i=0; i < iRows; i++) {        //Each row is made up of an array of Strings. Object[] rowObjs = new Object[iColumns]; for (int j=0; j < iColumns; j++) {           // Just to update the rows with different // data in alternate cycles. if( bToggle ) rowObjs[j] = new UIText("Data" + i + j, UIText.CENTERED); else rowObjs[j] = new UIText("Data" + j + i, UIText.CENTERED); }          UIRow row = new UIRow(rowObjs); viewer.add(row); }     if( bToggle ) bToggle = false; else bToggle = true; }

public boolean handleEvent(Event e)  { switch(e.id) {        case Event.WINDOW_DESTROY: System.exit(0); return true; default: return super.handleEvent(e); }  }    } // This thread updates the list periodically: // class UpdateThread extends Thread. {  private TestFrame pFrame = null; UpdateThread(TestFrame newFrame) {     pFrame = newFrame; start; }

public void run {     for {        pFrame.refresh; try { sleep(3000); } catch (InterruptedException ex) { } }  } }                     At a command prompt, type the following command to compile TestViewer.java:

jvc TestViewer.java

 At a command prompt, type the following command to run the TestViewer.class file:

jview TestViewer.class

 Use the thumb to scroll up and down. You can scroll properly until the contents are updated (about every 3 seconds), at which time the scrolling thumb jumps up and down in the scroll bar.

