Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Setting number of items to show in SWT List  RSS feed

 
Raja Kannappan
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have 200 items in my list and all the items show up on the screen. But, I want only to have 10 items to be visible and then have vertical scrollbar. How do I achieve this? I tried setting the bounds but that did not work. I'm using SWT inside eclipse forms. Below is my code. Any suggestions?

final Label myLabel = this.toolkit_.createLabel(myComposite, "Label: ", SWT.BEGINNING);

gridData = new GridData(SWT.BEGINNING, SWT.CENTER, false, false);

myLabel.setLayoutData(gridData);

this.myList_ = new org.eclipse.swt.widgets.List(myComposite, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL);

Point prefSize = this.myList_.computeSize(SWT.DEFAULT, SWT.DEFAULT);

Rectangle reqBounds = this.myList_.computeTrim(0, 0, prefSize.x, this.myList_.getItemHeight() * 10);

this.myList_.setBounds(10, 10, reqBounds.width, reqBounds.height);

gridData = new GridData(SWT.FILL, SWT.BEGINNING, true, false);

this.myList_.setLayoutData(gridData);

this.toolkit_.adapt(this.myList_, true, true);

Thanks in advance,

- Raja.
 
Raja Kannappan
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I found a solution to this myself.

There is no direct method to set the number of items in SWT list. But, you can indirectly control it by setting the heightHint in the GridData (if you are using GridLayout) for that component. So, the solution is to have the layout help in controlling the size of SWT list.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!