Project: SWT
Bug 11498 StyledText does not always redraw when the line style changes
Reported: 2002-03-15 17:28:51 | Status: resolved fixed

Build 20020312 In the following code, we attempt to change the color of the line that contains the caret while the caret is moving. To see the problem: 0) use the arrow keys to move the caret to another line - line style listener called, line color is changed 1) press the button - the widget redraws, showing where the line should be Knut: We belive that the line color background should be changed when the callback is called. Also, why is the callback called 3 times for every caret move? import org.eclipse.swt.SWT; import org.eclipse.swt.custom.*; import org.eclipse.swt.widgets.*; import org.eclipse.swt.events.*; import org.eclipse.swt.graphics.*; public class StyledBug { public static void main (String [] args) { Shell shell = new Shell(); shell.setText("Avocado Bug Test"); final StyledText text = new StyledText(shell,SWT.BORDER|SWT.V_SCROLL|SWT.H_SCROLL); text.setBounds(10,10,480,560); final Color SWT_COLOR_AVOCADO = new Color(shell.getDisplay(), 225, 235, 224); text.addLineStyleListener(new LineStyleListener(){ public void lineGetStyle(LineStyleEvent event){ int line = text.getLineAtOffset(event.lineOffset); int start = text.getOffsetAtLine(line); int end = start + event.lineText.length(); int p = text.getCaretOffset(); System.out.println("lineGetStyle"); if( p >= start && p <= end){ event.styles = new StyleRange[1]; StyleRange avacadoStyle = new StyleRange (); avacadoStyle.start = start; avacadoStyle.length = end; avacadoStyle.background = SWT_COLOR_AVOCADO; event.styles[0] = avacadoStyle; } } }); text.setEditable(true); String words[] = {"public","import","class","interface","try", "int","extends","throws","implements","double","float", "felipe","steveo","silenio","swt","veronika", "test","oti","blabla","13241234","style","helloworld"}; int length = words.length; for (int i = 1; i < 500; i++) { text.append(words[ (int) ( Math.random() * words.length ) ] + " "); if(i%9 == 0) text.append("\n"); } Button button = new Button(shell,SWT.PUSH); button.setText("Redraw"); button.setBounds(260,580,60,20); button.addMouseListener(new MouseAdapter(){ public void mouseDown(org.eclipse.swt.events.MouseEvent e){ text.redraw(); text.setFocus(); } }); shell.setSize(520,638); shell.open(); Display display = shell.getDisplay (); while (!shell.isDisposed ()) if (!display.readAndDispatch ()) display.sleep (); shell.dispose(); SWT_COLOR_AVOCADO.dispose(); } }

Files changed in fix:
bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledText.java