【问题标题】:Layouting the parent of a parent of a parent布局父级的父级
【发布时间】:2013-04-27 15:37:30
【问题描述】:

我们有一个工具,它有一个包含多个Sections 的 GUI。在这些部分中,我们有Expandable Composites,默认情况下不展开。当我们尝试扩展这些组合时,+ 变为 -,但它保持关闭状态:

为了解决这个问题,我尝试添加一个 ExpansionListener:

ExpandableComposite extendedConfiguration = getToolkit().createExpandableComposite(parent, TREE_NODE);
extendedConfiguration.setLayoutData(new GridData(FILL, CENTER, true, false, 2, 1));
extendedConfiguration.setText("Erweiterte Einstellungen");
extendedConfiguration.setExpanded(false);
extendedConfiguration.addExpansionListener(new ExpansionAdapter() {
    @Override
    public void expansionStateChanged(ExpansionEvent e) {
        parent.getParent().getParent().layout();
    }
});

使用这个脏代码,它可以工作,parent 是父级的复合。 parent的parent就是Section本身,Section的parent就是我们的view。它不仅看起来很愚蠢,而且当我们想改变我们的观点时也会出现问题,因为父级的父级......可能不是正确的父级。

再次布局视图的正确方法是什么?如何强制 UI 绘制 ExpandableComposite 的内容?

【问题讨论】:

  • 您是否尝试过使用 pack(); 而不是 layout(); ?如果你使用 org.eclipse.forms.ui.Form 你也可以试试form.reflow(true); 而不是layout();
  • @jens-na:我没有使用表单,它只是一个组合。此外, pack() 在这里没有帮助。
  • 应该展开的内容应该是可展开组合的客户端。例如:extendedConfiguration.setClient(contentComposite);。你的代码中有这样的东西吗?
  • @jens-na 是的,组合设置为客户端。复合的父级也是extendedConfiguration,如setClient 所述。

标签: java eclipse layout swt


【解决方案1】:

我认为只需触发 resize 事件就可以解决问题

 parent.getParent().layout(true);
 parent.getParent().notifyListeners(SWT.Resize, null);

【讨论】:

    【解决方案2】:

    首先:尝试使您的复合组件无效。

    【讨论】:

      【解决方案3】:

      你可以做一个顶层窗口的布局:

      extendedConfiguration.getShell().layout();
      

      来源:SWT counterpart of revalidate method of SWING's JComponent

      【讨论】:

      • 它什么也没做 :(.
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-31
      • 1970-01-01
      • 2020-10-15
      • 2023-03-31
      相关资源
      最近更新 更多