【问题标题】:How to disable scrollbar in ScrolledForm?如何在 ScrolledForm 中禁用滚动条?
【发布时间】:2013-07-05 09:20:28
【问题描述】:

ScrolledForm 的滚动条有时会​​导致问题。我在this guy in EclipseZone Forum 上遇到了同样的问题(这是 2005 年提出的问题,但似乎没有解决)。

//The scrollbar should only be displayed in the TreeViewer,not the whole form

【问题讨论】:

  • 所以不要使用滚动表单。使用不同的容器。
  • @jarodeells 那是因为 ManagedForm 的方法 getForm() 返回一个 ScrolledForm。(help.eclipse.org/indigo/…)
  • 你能用@janhink 的例子解决你的问题吗?我遇到了同样的问题,但无法让该解决方案发挥作用,所以你找到了一个可以解决的问题。我很好奇如何让它发挥作用。

标签: java swt jface eclipse-plugin


【解决方案1】:

这个问题我遇到过好几次,都是这样解决的:

@Override
protected void createFormContent(IManagedForm managedForm) {
    // set the form's body's layout to GridLayout
    final Composite body = managedForm.getForm().getBody();
    body.setLayout(new GridLayout());

    // create the composite which should not have the scrollbar and set its layout data
    // to GridData with width and height hints equal to the size of the form's body
    final Composite notScrolledComposite = managedForm.getToolkit().createComposite(body);
    final GridData gdata = GridDataFactory.fillDefaults()
            .grab(true, true)
            .hint(body.getClientArea().width, body.getClientArea().height)
            .create();
    notScrolledComposite.setLayoutData(gdata);

    // add resize listener so the composite's width and height hints are updates when
    // the form's body resizes
    body.addControlListener(new ControlAdapter() {
        @Override
        public void controlResized(ControlEvent e) {
            super.controlResized(e);
            gdata.widthHint = body.getClientArea().width;
            gdata.heightHint = body.getClientArea().height;
            notScrolledComposite.layout(true);
        }
    });
}

注意表单正文中的GridLayout,然后将宽度和高度hint 设置为组合的GridLayoutData

还要注意主体上的调整大小侦听器,它会更新网格布局数据并布局组合。

希望对你有帮助!

【讨论】:

  • 感谢您的代码示例。我尝试使用 notScrolledComposite 作为我的 SashForm 的父 Composite,而不是删除右侧的滚动条,整个内部控件消失了。使用此修复程序时,您需要做一些特别的事情吗?
  • 你给notScrolledComposite设置了合适的布局吗?
猜你喜欢
  • 1970-01-01
  • 2014-01-13
  • 1970-01-01
  • 2013-09-21
  • 2020-11-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-04-06
相关资源
最近更新 更多