Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » PaintListener not listening(It appears my PaintListner never gets called and I don't know why!)
PaintListener not listening [message #1726406] Sat, 12 March 2016 20:22 Go to next message
Mark Fenbers is currently offline Mark FenbersFriend
Messages: 64
Registered: July 2009
Location: Ohio, USA
Member
I'm creating a new widget by extending Canvas. My code has been uploaded. In the main code, after instantiating the widget, I call setHydrograph(), which calls redraw(), which fires a Paint event (supposedly). But my Paint Event handler never prints the flagging text. All (or most) of the other event handlers (like, for Mouse action or the dispose event) get called, and the flagging text gets written.

I've reworked this code several times, and studied other examples online, and cannot detect anything I am doing wrong. Do you have any ideas why my Paint handler doesn't seem to get called?

Mark
Re: PaintListener not listening [message #1726413 is a reply to message #1726406] Sun, 13 March 2016 04:25 Go to previous messageGo to next message
Brian de Alwis is currently offline Brian de AlwisFriend
Messages: 693
Registered: January 2012
Senior Member

Your code doesn't actually have any 'flagging text' for your paint events:

this.addPaintListener(new PaintListener() {
			@Override
			public void paintControl(PaintEvent e) {
				HGviewer.this.paintControl(e);
			}
		});


Since you're seeing mouse messages, it seems safe to assume that your widget has an expected size. Instead of drawing an image, set the background to a standard system colour and do a fillRectangle of your widget area. At least then you should be able to tell if your paint event is happening or whether there's a deeper issue with your image being drawn.


Eclipse Platform committer. Ask me about Eclipse support, training, and consulting.
Re: PaintListener not listening [message #1726419 is a reply to message #1726413] Sun, 13 March 2016 10:50 Go to previous messageGo to next message
Mark Fenbers is currently offline Mark FenbersFriend
Messages: 64
Registered: July 2009
Location: Ohio, USA
Member
Thanks for helping and making suggestions. Sorry about the missing "flagging" text. I didn't realize that I didn't replace it before uploading the file. But even when it is there, the results are the same -- that the Paint Event is not handled.

I also have a setBackground call (to RED) in the constructor, but based on your advice, I now do this in the Paint handler using GC (DARK_GREEN). Again, this doesn't happen because the Paint handler is not called.

I cannot figure out why the Paint handler is not called. I've uploaded a new file addressing the issues you mentioned.
Re: PaintListener not listening [message #1727401 is a reply to message #1726419] Tue, 22 March 2016 17:40 Go to previous messageGo to next message
Erdal Karaca is currently offline Erdal KaracaFriend
Messages: 840
Registered: July 2009
Senior Member
Do you make sure that the parent of your Canvas has a layout set?
AFAIR, painting will only occur if the widget/control is "visible".
Re: PaintListener not listening [message #1727402 is a reply to message #1727401] Tue, 22 March 2016 17:45 Go to previous messageGo to next message
Mark Fenbers is currently offline Mark FenbersFriend
Messages: 64
Registered: July 2009
Location: Ohio, USA
Member
Good point! I'll check into that. There may not be a "layout" per se, but the shell does reserve the correct size that I specify with .setSize(w,h).
Mark
Re: PaintListener not listening [message #1727952 is a reply to message #1727401] Tue, 29 March 2016 18:31 Go to previous messageGo to next message
Mark Fenbers is currently offline Mark FenbersFriend
Messages: 64
Registered: July 2009
Location: Ohio, USA
Member
The parent of my Canvas is a ScrolledComposite. I created a FillLayout and set it to the Scrolled Composite:
FillLayout fl = new FillLayout();
sc.setLayout(fl);

But this did nothing to help my problem. I even tried using a setLayoutData() on my Canvas. Nothing changes. the PaintListener never seems to get called. Still scratching the noggin!
Mark
Re: PaintListener not listening [message #1727955 is a reply to message #1727401] Tue, 29 March 2016 19:20 Go to previous message
Mark Fenbers is currently offline Mark FenbersFriend
Messages: 64
Registered: July 2009
Location: Ohio, USA
Member
I solved it. I was creating my Canvas with a SWT.CENTER style bit OR'd with other styles. It didn't like that! Thanks for the help!
Mark
Previous Topic:Need to have Copy and paste feature in SWT Table to clipboard/other table
Next Topic:Create Modeless WizardDialog
Goto Forum:
  


Current Time: Mon Dec 11 00:28:06 GMT 2017

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

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