PRB: Scroll Box Jumps Up and Down in UIColumnViewer Class Object (238830)



The information in this article applies to:

  • Microsoft SDK for AFC 1.0
  • Microsoft SDK 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.

MORE INFORMATION

Steps to Reproduce the Behavior

  1. 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) { }
          }
       }
    }
    					
  2. At a command prompt, type the following command to compile TestViewer.java:

    jvc TestViewer.java

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

    jview TestViewer.class

  4. 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.

REFERENCES

For support information about Visual J++ and the SDK for Java, visit the following Microsoft Web site:

Modification Type:MajorLast Reviewed:6/14/2006
Keywords:kbJAFC kbprb KB238830