如何使用分隔线上的箭头按钮(或类似按钮)移动/调整窗框的窗框?

时间:2014-12-08 06:27:44

标签: java forms resize swt divider

在我的RCP应用程序中,我使用了横向SashForm。可以使用分隔线移动窗扇。但我需要在分隔线上使用按钮(左/右)移动我的腰带。

如何在分隔线上创建具有按钮的窗扇形式,以将窗扇向左或向右移动到特定宽度?我在互联网上搜索,但没有找到任何相关的答案。

2 个答案:

答案 0 :(得分:1)

由于SashForm没有此类属性,因此预期行为无法直接生成。但它可以使用我们自己的CustomSashForm。

请看下面的网址,他们已经编写了自己的SashForm来达到要求,这解决了我的问题:

http://svn.bonitasoft.org/bonita-studio/tags/bonita-studio-5.8/plugins/org.bonitasoft.studio.groovy.ui/src/org/bonitasoft/studio/groovy/ui/dialog/BonitaSashForm.java

感谢您的所有回复。 :)

答案 1 :(得分:0)

每次单击相应按钮时,下面的代码会将窗框向左或向右移动约1px。

private static int middle = 0;

public static void main(String[] args)
{
    final Display display = new Display();
    Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());

    final SashForm form = new SashForm(shell, SWT.HORIZONTAL);

    final Button left = new Button(form, SWT.PUSH);
    final Button right = new Button(form, SWT.PUSH);

    left.setText("Left");
    right.setText("Right");

    Listener listener = new Listener()
    {
        @Override
        public void handleEvent(Event event)
        {
            if(event.widget.equals(left))
                middle++;
            else
                middle--;

            int[] weights = new int[]{1, 1};

            int width = form.getClientArea().width;

            weights[0] = (int)Math.round(width / 2f + middle);
            weights[1] = (int)Math.round(width / 2f - middle);

            form.setWeights(weights);
        }
    };

    left.addListener(SWT.Selection, listener);
    right.addListener(SWT.Selection, listener);

    form.setWeights(new int[] { 1, 1 });

    shell.pack();
    shell.open();

    while (!shell.isDisposed())
    {
        if (!display.readAndDispatch())
        {
            display.sleep();
        }
    }
    display.dispose();
}

看起来像这样:

enter image description here

在左侧按钮上单击十次,它看起来像这样:

enter image description here