Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Graphic Context in View
Graphic Context in View [message #447116] Wed, 08 December 2004 20:13 Go to next message
Eclipse UserFriend
Originally posted by: duc_niit.yahoo.co.uk

I have a view and I wanna use graphic context to drawing a line.Here is my
code but I see nothing.Can anybody tell me why ?.Thanks a lot

public void createPartControl(Composite parent)
{
display = parent.getDisplay();

toolkit = new FormToolkit(parent.getDisplay());
form = toolkit.createScrolledForm(parent);
form.setBackground(new
org.eclipse.swt.graphics.Color(org.eclipse.swt.widgets.Displ ay.getDefault(),
255, 255, 255));
form.setSize(800,600);

GC gc = new GC(form.getDisplay(),SWT.NONE);
gc.drawLine(100,100,500,500);
gc.dispose();
}

public void setFocus()
{
form.setFocus();
}

public void dispose() {
toolkit.dispose();
super.dispose();
}
}
Graphic Context in View [message #447157 is a reply to message #447116] Thu, 09 December 2004 09:54 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: duc_niit.yahoo.co.uk

Noone has a solution ???
Please help me because I need to using graphic context on my porject
Re: Graphic Context in View [message #447160 is a reply to message #447116] Thu, 09 December 2004 11:33 Go to previous messageGo to next message
Stefan Zeiger is currently offline Stefan ZeigerFriend
Messages: 102
Registered: July 2009
Senior Member
mylove wrote:

> public void createPartControl(Composite parent)
> {
> display = parent.getDisplay();
>
> toolkit = new FormToolkit(parent.getDisplay());
> form = toolkit.createScrolledForm(parent);
> form.setBackground(new
> org.eclipse.swt.graphics.Color(org.eclipse.swt.widgets.Displ ay.getDefault(),
> 255, 255, 255));
> form.setSize(800,600);
> GC gc = new GC(form.getDisplay(),SWT.NONE);
> gc.drawLine(100,100,500,500);
> gc.dispose();
> }

You cannot just draw on an SWT Control at any time. Controls in SWT are
not double buffered. You need to register a Paint listener and do the
painting on the PaintEvent's GC whenever you get a PaintEvent.

--
Stefan Zeiger http://www.szeiger.de http://www.novocode.com
My SWT controls: http://www.novocode.com/swt
Re: Graphic Context in View [message #447220 is a reply to message #447116] Thu, 09 December 2004 18:56 Go to previous message
Ivan Markov is currently offline Ivan MarkovFriend
Messages: 61
Registered: July 2009
Member
1. You are trying to draw directly on the desktop instead of on the control
which the view wraps. (form.getDisplay())
2. As the other poster mentioned, the way you do it (not in PaintListener)
will result in the fact that if your control got obscured by another window,
it will not repaint itself properly.


"mylove" <duc_niit@yahoo.co.uk> wrote in message
news:cp7na6$f5h$1@www.eclipse.org...
> I have a view and I wanna use graphic context to drawing a line.Here is my
> code but I see nothing.Can anybody tell me why ?.Thanks a lot
>
> public void createPartControl(Composite parent)
> {
> display = parent.getDisplay();
>
> toolkit = new FormToolkit(parent.getDisplay());
> form = toolkit.createScrolledForm(parent);
> form.setBackground(new
>
org.eclipse.swt.graphics.Color(org.eclipse.swt.widgets.Displ ay.getDefault(),
> 255, 255, 255));
> form.setSize(800,600);
>
> GC gc = new GC(form.getDisplay(),SWT.NONE);
> gc.drawLine(100,100,500,500);
> gc.dispose();
> }
>
> public void setFocus()
> {
> form.setFocus();
> }
>
> public void dispose() {
> toolkit.dispose();
> super.dispose();
> }
> }
>
Previous Topic:Formatted Text
Next Topic:Messenger Style Notifications
Goto Forum:
  


Current Time: Wed Oct 28 14:32:27 GMT 2020

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

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

Back to the top