Styled Text setText have bad perfomance

278 views Asked by At

I have little problem with StyledText. When I use setText() Method and text is long, I must wait few seconds for render that text. Is there any method what can I use to speed up showing this text?

1

There are 1 answers

1
Georgian On

The only optimisation you can implement is putting your setText() in a Job or in a Runnable to not block the UI.

Other than that, it's an API limitation from SWT.

Other suggestions:

  • File a bug/feature request
  • Search for a StyledText, although apparently none exist
  • Rethink your program. Don't you have a backup plan? Is the performance critical?


    Edit:

    @greg-449

    /**
     * 
     * @author ggrec
     *
     */
    public class Test
    {
        public static void main(final String[] args)
        {
            new Test();
        }
    
        private Test()
        {
            final Display display = new Display();
            final Shell shell = new Shell(display);
            shell.setLayout(new GridLayout(1, false));
    
            final Button button = new Button(shell, SWT.PUSH);
            button.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
            button.setText("Press me");
    
            final StyledText text = new StyledText(shell, SWT.NONE);
            text.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    
            button.addSelectionListener(new SelectionAdapter() 
            {
                @Override public void widgetSelected(final SelectionEvent e)
                {
                    Display.getDefault().asyncExec(new Runnable() 
                    {
                        @Override public void run()
                        {
                            text.setText("*put very long text here*");
                        }
                    });
                }
            });
    
            shell.setSize(1000, 1000);
            shell.open();
            while (!shell.isDisposed())
            {
                if ( !display.readAndDispatch() )
                    display.sleep();
            }
            display.dispose();
        }
    }