1
我實現了一個Java SWT SashForm 3個窗格:的Java SWT調整大小TRIPPLE 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);
}
}
});
我的問題是,滑動執行是生澀和緊張,絕對不光滑。有沒有更好的方式來獲得相同的效果,只是平滑而沒有生澀的行爲?
這除了提高事情有點,但我還是看到了生澀的行爲,更不用說來回,像控制試圖打我運動。這可能與weight屬性是一個整數有關。其實,恕我直言,整個「重量」概念在這種情況下是有缺陷的。我應該能夠指定每個窗框的大小。 – 2014-10-07 14:07:45