tags:

views:

123

answers:

0

So I ran into an issue with SWT Trees and I wanted to know if anyone knows why this is happening and what the work around is (if there is one).

If you create a tree and then put into it a large number of elements, then proceed to expand them all, you will notice something odd - the scroll bar on the side disappears. The values are still in the tree - you can get to them by using the key-down, but you can no longer scroll to them.

Note that it only happens when you have the magic number of 65535 elements or more - probably not coincidental that this is the length of a short... but I don't see where the offending short is.

Any thoughts on this and how I might be able to get around it?

Thanks much,

-Ritter

Code snippet to see the issue (just expand both roots and voila! no scroll bar):

public TreeTest(final Shell shell)
{
     final Tree tree = new Tree(shell, SWT.VIRTUAL | SWT.BORDER);

     final TreeItem item1 = new TreeItem(tree, SWT.NULL);
     item1.setText("node 1");
     for(int i = 0; i < 65530; i++)
     {
        final TreeItem item11 = new TreeItem(item1, SWT.NULL);
        item11.setText("Node " + i);
     }

     final TreeItem item2 = new TreeItem(tree, SWT.NULL);
     item1.setText("node 2");
     for(int i = 0; i < 5; i++)
     {
        final TreeItem item21 = new TreeItem(item2, SWT.NULL);
        item11.setText("Node " + i);
     }
 }

 public static void main(String[] args)
 {
     Display display = new Display();
     Shell shell = new Shell(display);
     shell.setLayout(new FillLayout());
     new TreeTest(shell);
     shell.open();
     while(!shell.isDisposed)
     {
          if(!display.readAndDispatch())
          {
              display.sleep();
          }
     }
     display.dispose();
 }