gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 06:30:09 32 4
gpt4 key购买 nike

我实现了一个具有 3 个 Pane 的 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);

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

我希望能够通过拖动中间来调整表单的大小。用户单击中间并向左或向右拖动,从而保持中间 Pane 固定,只需向左或向右滑动。我能够按如下方式实现此功能:

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);

关于Java SWT 平滑调整 Tripple SashForm 常量中间大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26222160/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com