Java SWT调整三重SashForm常量中间平滑
我实现了一个带有3个窗格的Java SWT表单:Java SWT调整三重SashForm常量中间平滑,java,resize,swt,Java,Resize,Swt,我实现了一个带有3个窗格的Java SWT表单: 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)
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);
这一添加使情况有所改善,但我仍然看到了不稳定的行为,更不用说来回移动了,就像控制装置试图阻止我的移动一样。这可能与权重属性是整数有关。事实上,在这种情况下,整个“重量”概念是有缺陷的。我应该能够指定每个窗扇的大小。