Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Why do newly created elements in a Java SWT Selection listener not get displayed/trigger a paint eve
Why do newly created elements in a Java SWT Selection listener not get displayed/trigger a paint eve [message #1067014] Fri, 05 July 2013 12:59
Tobias Pfeiffer is currently offline Tobias PfeifferFriend
Messages: 1
Registered: July 2013
Junior Member
Hi everyone,

As a quick note: I have also posted this as this on Stack overflow but the forum won|t let me link to it.... Title and most of the content are the same.

I've got a problem with SWT (standard widget toolkit) and redrawing. Basically I want something to happen when I click a button e.g. new elements to appear. For the sake of simplicity let it be text here.

However when I click the button nothing happens, no element appears, no PaintEvent is triggered. When I resize the window, suddenly all of the elements are there (because that triggers a paintEvent/redrawing).

The docs and blog posts tell me that a paint event is triggered whenever something needs to be redrawn. I thought that adding a new element to an application would fall into that category.

So the question is: Am I doing something wrong here? Am I supposed to call layout()/redraw() by hand to trigger the redraw? That seems tedious to me and to my understanding was that SWT handles that for me for the most cases.

Oh I'm running Linux x64 with SWT 4.2.2. But we have this on pretty much any platform (and also on the old SWT 3.7).

And here goes my little example code:

    import org.eclipse.swt.*;
    import org.eclipse.swt.widgets.*;
    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");
    				// Why do these texts not show up and not trigger a Paint Event?
    		shell.setLayout (new RowLayout());
    		shell.addPaintListener(new PaintListener() {
    			public void paintControl(PaintEvent e) {
    				// just triggered in the beginning and with resizes
    				System.out.println("Hooray we got a Paint event");
    		while (!shell.isDisposed()) {
    			if (!display.readAndDispatch()) display.sleep();

Please keep in mind, that this is not purely about making that example just work. This is a simple version of a problem for a much bigger project Smile

Any help is well appreciated!

Thanks + cheers!
Previous Topic:Problem with "org.eclipse.swt.SWTError: No more handles"
Next Topic:Create a rectangle of selection
Goto Forum:

Current Time: Fri May 25 16:45:26 GMT 2018

Powered by FUDForum. Page generated in 0.01463 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top