java 如何滚动复合?

d8tt03nd  于 2022-12-10  发布在  Java
关注(0)|答案(1)|浏览(121)

我已经得到了:

private void createTab(){

  TabItem mvTabItem = new TabItem( tabFolder, SWT.NONE );
  mvTabItem.setText( TabHeader.modelviews.getTabHeaderName() );

  Composite mvContainer = new Composite( tabFolder, SWT.V_SCROLL );
  mvContainer.setLayout( new GridLayout(1, false) );
  mvContainer.setLayoutData( new GridData(GridData.FILL, GridData.FILL, true, true) );

  mvTabItem.setControl( mvContainer );

  // Selection of model views
  createSelectionGroup(mvContainer);

  // other code, more groups created
}

创建选项卡项,添加垂直滚动条,但是滚动不起作用。为什么?
createSelectionGroup(mvContainer)中也有一个滚动条。这个滚动条工作正常,没有应用org.eclipse.swt.custom.ScrolledComposite

private void createSelectionGroup(Composite parent)
{
  // Create group component.
  Group grpMVselection = new Group(parent, SWT.SHADOW_IN);
  grpMVselection.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true));
  grpMVselection.setText(SelectionLabelStr);
  grpMVselection.setLayout(new GridLayout(1, true));

  // another code, added buttons, listeners
    
  final SashForm sashForm = new SashForm(grpMVselection, SWT.VERTICAL | SWT.BORDER);
  sashForm.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));

  // srolling applied 
  selectionTree = new CheckboxTreeViewer(sashForm, SWT.SINGLE | SWT.V_SCROLL | SWT.H_SCROLL | SWT.HIDE_SELECTION);
  selectionTree.getTree().setLayoutData( new GridData( SWT.BEGINNING, SWT.BEGINNING, true, true ) );
}

有类似的问题公布,但我不能应用答案到我的代码。我尝试:
1.将Composite mvContainer更改为ScrolledComposite,没有帮助
1.将mvContainer插入到ScrolledComposite,没有帮助

TabItem mvTabItem = new TabItem( tabFolder, SWT.NONE );
 mvTabItem.setText( TabHeader.modelviews.getTabHeaderName() );

 final ScrolledComposite sc = new ScrolledComposite(tabFolder, SWT.V_SCROLL );
 sc.setExpandVertical(true);

 mvTabItem.setControl(sc);

 Composite mvContainer = new Composite( sc, SWT.NONE );
 //mvContainer.setLayout(new GridLayout());
 mvContainer.setLayout( new GridLayout(1, false) );
 mvContainer.setLayoutData( new GridData(GridData.FILL, GridData.FILL, true, true) );

 sc.setContent(mvContainer);

孩子们需要改变一些属性吗?谢谢任何提示!!!

7cwmlq89

7cwmlq891#

您确实需要使用ScrolledComposite来滚动复合图像。
类似于:

final TabItem tabItem = new TabItem(tabFolder, SWT.NONE);
tabItem.setText("Tab");

final ScrolledComposite sc = new ScrolledComposite(tabFolder, SWT.V_SCROLL | SWT.H_SCROLL);
sc.setExpandHorizontal(true);
sc.setExpandVertical(true);

tabItem.setControl(sc);

final Composite scrolledComp = new Composite(sc, SWT.NONE);
scrolledComp.setLayout(new GridLayout());

sc.setContent(scrolledComp);

// Example contents
for (int i = 1; i <= 100; i++)
  new Label(scrolledComp, SWT.LEAD).setText("Label " + i);

sc.setMinSize(scrolledComp.computeSize(SWT.DEFAULT, SWT.DEFAULT));

CheckboxTreeViewer之类的TreeViewer可以自己滚动,但Composites需要ScrollledComposite。

相关问题