I have a problem with SWT (standard widget toolkit) and redrawing. Basically I want something to happen when I press a button, for example. new items will appear. For simplicity, let it be the text here.
However, when I click the button, nothing happens, the element does not appear, PaintEvent does not start. When I resize the window, all the elements suddenly appear (because it causes paintEvent / redraw).
Docs and blogs have reported that a drawing event is fired whenever something needs to be redrawn. I thought adding a new item to the application would fall into this category.
So the question is, am I doing something wrong here? Should I call layout () / redraw () manually to trigger a redraw? This seems tedious to me, and as I understand it, SWT handles this for me in most cases.
Oh, I am running Linux x64 with SWT 4.2.2. But we have it on almost any platform (as well as on the old SWT 3.7).
And here is my little sample code:
import org.eclipse.swt.*; import org.eclipse.swt.widgets.*; import org.eclipse.swt.events.*; import org.eclipse.swt.layout.*; public class MainExample { public static void createText(Shell shell) { Text text = new Text(shell, SWT.SINGLE); text.setText("here is some fancy text"); } public static void main (String [] args) { Display display = new Display (); Shell shell = new Shell (display); Button button = new Button(shell, SWT.PUSH); button.setText("I am a button"); button.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { System.out.println("Button Clicked");
Please keep in mind that the point is not only to make this example work. This is a simple version of the problem for a much larger project :-)
Any help is appreciated!
source share