我有一个窗扇触发StyledText的大小调整以及它所在的ExpandItem的高度。它变得“跳跃”。换句话说,StyledText倾向于扩展到所需的大小,然后在调整大小时恢复到原始大小。最终,一切都落在了正确的位置,但这是一个丑陋的过渡。
我可以在下面的代码中更改什么来摆脱“跳跃”?
public static void main(String[] args) {
final Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new FillLayout(SWT.VERTICAL));
shell.setSize(400, 400);
//Create the expand bar
ExpandBar expandBar1=new ExpandBar(shell,SWT.None);
//Create the first expand item.
final ExpandItem expandItem1=new ExpandItem(expandBar1,SWT.None);
final Composite composite=new Composite(expandBar1,SWT.NONE);
final RowLayout layout=new RowLayout(SWT.VERTICAL);
composite.setLayout(layout);
expandItem1.setControl(composite);
expandItem1.setHeight(100);
//Add text
final StyledText one=new StyledText(composite,SWT.BORDER|SWT.MULTI|SWT.WRAP|SWT.V_SCROLL);
one.setText("aaaa\nbbbbbb\nccccc\ndddd");
//Add a sash
final Sash sash1=new Sash(composite,SWT.HORIZONTAL);
sash1.setSize(sash1.getSize().x, 10);
sash1.addListener(SWT.Selection,new Listener(){
@Override
public void handleEvent(Event event) {
one.setSize(one.getSize().x,event.y);
sash1.setLocation(0, event.y+5);
expandItem1.setHeight(event.y+10);
composite.redraw();
}
});
//Create the second expand item.
ExpandItem expandItem2=new ExpandItem(expandBar1,SWT.None);
Composite composite2=new Composite(expandBar1,SWT.None);
composite2.setLayout(new FillLayout());
StyledText two=new StyledText(composite2,SWT.V_SCROLL);
two.setText("two\nabadfae\nasdfaef\nadfef\nesfj;lef\nefsfe\nasefae\n...");
expandItem2.setControl(composite2);
expandItem2.setHeight(100);
//Final junk
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) display.sleep();
}
display.dispose();
}
注意:请随意提供有关改进此代码的任何其他提示。我是SWT的新手。