Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Problem in Canvas Redraw
Problem in Canvas Redraw [message #717146] Fri, 19 August 2011 12:24 Go to next message
Balaji  is currently offline Balaji Friend
Messages: 17
Registered: August 2011
Junior Member
Hi
I am Loading an image to canvas. It successfully loaded.

But when I minimize the and restore back to CANVAS window, the image was lost.

Then I have to call to redraw() and repaint the image again.

Whats the reason for clearing the Canvas? Is there any FLAG to set?
Re: Problem in Canvas Redraw [message #718506 is a reply to message #717146] Wed, 24 August 2011 14:09 Go to previous messageGo to next message
Grant Gayed is currently offline Grant GayedFriend
Messages: 2151
Registered: July 2009
Senior Member
I assume you're drawing the Image to the Canvas with something like
GC.drawImage(...). If so, it sounds like you're not doing it in a
SWT.Paint callback, which is where this needs to be done. For an
example of this see
http://git.eclipse.org/c/platform/eclipse.platform.swt.git/tree/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet245.java
..

Another snippet that may be helpful:
http://git.eclipse.org/c/platform/eclipse.platform.swt.git/tree/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet48.java
..

Grant


On 8/19/2011 8:24 AM, Balaji wrote:
> Hi
> I am Loading an image to canvas. It successfully loaded.
> But when I minimize the and restore back to CANVAS window, the image was
> lost.
> Then I have to call to redraw() and repaint the image again.
>
> Whats the reason for clearing the Canvas? Is there any FLAG to set?
Re: Problem in Canvas Redraw [message #719164 is a reply to message #718506] Fri, 26 August 2011 08:50 Go to previous messageGo to next message
Balaji  is currently offline Balaji Friend
Messages: 17
Registered: August 2011
Junior Member
Hi
Thanks for your reply. Hope the following code sample is same as the example you've pointed.

Sample Code:


{
...
canvas.addPaintListener(new StartScribble());
..
..
}

private class MYPAINT implements PaintListener {
		    public void paintControl( PaintEvent e) {
    	  	              gc.drawRectangle(100,200 ,width,height);
		      gc.dispose();
		    }
		  }





If anything is wrong in that can you please point out
Re: Problem in Canvas Redraw [message #719947 is a reply to message #719164] Mon, 29 August 2011 14:22 Go to previous messageGo to next message
Grant Gayed is currently offline Grant GayedFriend
Messages: 2151
Registered: July 2009
Senior Member
In the paint listener make sure you're using the GC from the event
(e.gc), not a GC of your own (gc). Also, you cannot dispose() the GC
from the event since you did not create it.

Grant


On 8/26/2011 4:50 AM, Balaji wrote:
> Hi
> Thanks for your reply. Hope the following code sample is same as the
> example you've pointed.
> Sample Code:
>
>
>
> {
> ..
> canvas.addPaintListener(new StartScribble());
> .
> .
> }
>
> private class MYPAINT implements PaintListener {
> public void paintControl( PaintEvent e) {
> gc.drawRectangle(100,200 ,width,height);
> gc.dispose();
> }
> }
>
>
>
>
>
> If anything is wrong in that can you please point out
Re: Problem in Canvas Redraw [message #719971 is a reply to message #719947] Mon, 29 August 2011 15:26 Go to previous messageGo to next message
Balaji  is currently offline Balaji Friend
Messages: 17
Registered: August 2011
Junior Member
Thanks again Grant...
This time I tried in this way but the result is same.


Public GC gc;        // ADDED NEW

{
...
gc = new GC(canvas);  // ADDED NEW
...
...
canvas.addPaintListener(new StartScribble());
..
..
}

private class MYPAINT implements PaintListener {
		    public void paintControl( PaintEvent e) {
    	  	              gc.drawRectangle(100,200 ,width,height);

                             // gc.dispose   // REMOVED

		    }
		  }




[Updated on: Mon, 29 August 2011 15:29]

Report message to a moderator

Re: Problem in Canvas Redraw [message #720180 is a reply to message #719971] Tue, 30 August 2011 04:11 Go to previous messageGo to next message
Vijay RajFriend
Messages: 608
Registered: July 2009
Senior Member
Pls refer SWT snippets,there are many examples of problems such,

for your scanario
http://git.eclipse.org/c/platform/eclipse.platform.swt.git/plain/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet48.java


---------------------
why, mr. Anderson, why, why do you persist?
Because I Choose To.
Regards,
Vijay
Re: Problem in Canvas Redraw [message #720195 is a reply to message #719971] Tue, 30 August 2011 05:42 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by:

On 2011-08-29 17:26, Balaji wrote:
> Thanks again...
> This time I tried in this way but the result is same.
>
>
>
> Public GC gc;
>
> {
> ..
> gc = new GC(canvas);
> canvas.addPaintListener(new StartScribble());
> .
> .
> }
>
> private class MYPAINT implements PaintListener {
> public void paintControl( PaintEvent e) {
> gc.drawRectangle(100,200 ,width,height);
> // gc.dispose
>
> }
> }

You have not really read Grant's description, which was very clear.

- Daniel Kr├╝gler
Re: Problem in Canvas Redraw [message #720398 is a reply to message #720195] Tue, 30 August 2011 14:01 Go to previous message
Balaji  is currently offline Balaji Friend
Messages: 17
Registered: August 2011
Junior Member
Thanks Daniel, Grant and Vijay
Sorry Smile
I tried the way what Grant mentioned, but still the result is same. I think I have to relook my application. Thanks again.

This an plugin application, so does it inherit any property of Base Application. Does this can be reason for this.? Because when I try to add Label with SWT.MULTI, I am getting a Vertical line (No Text is displayed)

http://www.eclipse.org/forums/index.php/m/641889/?srch=swt+label+size#msg_641889


[Updated on: Tue, 30 August 2011 15:49]

Report message to a moderator

Previous Topic:Windows 7: how to open e-mail client
Next Topic:set text input to overwrite/insert mode programatically
Goto Forum:
  


Current Time: Wed Nov 26 21:50:28 GMT 2014

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

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