Java SWT调整Tripple SashForm常量中间平滑



我实现了一个带有3个窗格的Java SWT SashForm:

SashForm oSash = new SashForm(cmptParent, SWT.NONE);
GridLayout gridLayout = new GridLayout();
gridLayout.numColumns = 3;
oSash.setLayout(gridLayout);
oSash.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true));
Composite oPaneLeft = new Composite(oSash, SWT.NONE);
...
Composite oPaneMiddle = new Composite(oSash, SWT.NONE);
...
Composite oPaneRight = new Composite(oSash, SWT.NONE);

这个想法是有一个固定大小的中间分区。设置初始宽度很简单。

我希望能够通过拖动中间来调整窗体的大小。用户单击中间并向左或向右拖动,从而保持中间窗格固定,只是向左或向右滑动。我能够实现以下功能:

private static Boolean sisResizeSashMiddle = false;
private static int siPosSashMiddleOffset = 0;
...
cmptPaneMiddle = new Composite(cmptParent, SWT.NONE);
cmptPaneMiddle.addMouseListener(new MouseAdapter()
{
    @Override
    public void mouseDown(MouseEvent arg0)
    {
        // The user wishes to resize the sash.
        AppMain.sisResizeSashMiddle = true;
        AppMain.siPosSashMiddleOffset = arg0.x - AppMain.siPosSashMiddleStart;
    }
    @Override
    public void mouseUp(MouseEvent arg0)
    {
        // The user finished resizing the sash.
        AppMain.sisResizeSashMiddle = false;
    }
});
cmptPaneMiddle.addMouseMoveListener(new MouseMoveListener()
{
    public void mouseMove(MouseEvent arg0)
    {
        // Only resize the sashes if user hold down the mouse while dragging.
        if (true == AppMain.sisResizeSashMiddle)
        {
            // Compute the width of each sash.
            int icxShell = shell.getSize().x;
            int icxLeft = arg0.x - AppMain.siPosSashMiddleOffset;
            int icxMiddle = AppMain.BrowserSash_Pane_Middle_Width;
            int icxRight = shell.getSize().x - icxLeft - icxMiddle;
            // Compute the weights.
            int iWeightLeft = 10000 * icxLeft / icxShell;
            int iWeightMiddle = 10000 * icxMiddle / icxShell;
            int iWeightRight = 10000 * icxRight / icxShell;
            // Set the weights.
        int[] weights = new int[] {iWeightLeft, iWeightMiddle, iWeightRight};
        oSash.setWeights(weights);
        }
    }
});

我的问题是,滑动实现是不稳定和不稳定的,绝对不是平稳的。有没有更好的方法来获得同样的效果,只是平稳而没有抽搐的行为?

尝试在SashForm:上使用SWT.SMOOTH标志

SashForm oSash = new SashForm(cmptParent, SWT.SMOOTH);

最新更新