2

我有一个触发 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 的新手。

4

0 回答 0