【问题标题】:How to load a part of composite keeping others static?如何加载复合材料的一部分保持其他静态?
【发布时间】:2017-06-16 15:23:40
【问题描述】:

我在 SWT 中有一个表单,其中我有五个基于一个父组合的不同组合。每个组合都包含不同的小部件,例如单个文本框/组合框/文本和组合的组合等。

现在的问题是,当我单击按钮时,我想更改我的第三个复合材料以携带不同的小部件以保持其他小部件保持静态。现在我无法从头重新加载,因为我希望显示其他小部件的当前值.我怎样才能只获取那个组合,处理它并创建一个新的小部件来代替它。

很难考虑创建和隐藏小部件,因为它在我们想要重绘的位置是动态的。

这里是sn-p。

    formComposite=new Composite(parentComposite,SWT.BORDER_SOLID);
    formLayout=new GridLayout(5,false);
    fromComposite.setLayout(formLayout)
    item.create(formComposite)  //Here item is the widget (combo/textbox/combination text/combo)

     formComposite1=new Composite(parentComposite,SWT.BORDER_SOLID);
    formLayout1=new GridLayout(5,false);
    fromComposite1.setLayout(formLayout)
    item1.create(formComposite1))

  formComposite2=new Composite(parentComposite,SWT.BORDER_SOLID);
    formLayout2=new GridLayout(5,false);
    fromComposite2.setLayout(formLayout)
    item2.create(formComposite2))

 formComposite3=new Composite(parentComposite,SWT.BORDER_SOLID);
    formLayout3=new GridLayout(5,false);
    fromComposite3.setLayout(formLayout)
    item3.create(formComposite3))

 formComposite4=new Composite(parentComposite,SWT.BORDER_SOLID);
    formLayout4=new GridLayout(5,false);
    fromComposite4.setLayout(formLayout)
    item4.create(formComposite4))

现在我如何将 item3 替换为要创建的其他项目,以保持其他项目保持不变?

【问题讨论】:

  • 注意:BORDER_SOLID 不是Composite 的有效样式。

标签: java layout swt


【解决方案1】:

假设每个Composite 只有一个子控件,您可以只处理现有控件并添加新控件,然后重做布局。

item.dispose();

item = new Combo(fromComposite, ... style);

formComposite.layout(true);

您可能还需要在parentComposite 上致电layout

【讨论】:

    【解决方案2】:

    您可以使用Control.moveAbove()Control.moveBelow() 方法来做到这一点

    // create item3replacement
    item3replacement.moveAbove(item3);
    item3.dispose();
    // call layout on parent when all is done
    

    否则您需要编写自己的Layout 才能这样做。 当您使用GridLayout 时,这将是您的起点。 您需要将位置值添加到GridData 并在GridLayout 中进行处理

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-03-15
      • 1970-01-01
      • 2020-06-27
      • 2016-04-21
      • 2022-01-08
      • 2018-05-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多