Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Canvas painting problem in the view of a simple plugin
Canvas painting problem in the view of a simple plugin [message #453453] Wed, 06 April 2005 02:09 Go to next message
Eclipse UserFriend
Originally posted by: aaa.domain.invalid

Hello,

I am trying to use the simple plugin with a view (eclipse sample plugin
with a view, by using the new plugin project).
Removed the table and added a canvas that simply paints the background
to start off with.

I would like to fix the size of the painted rectangle areas in the view tab.

The outer rectangle needs to be white and the inner one needs to be blue
and their size needs to be fixed through resizing of the windows.

<----x1------>
-------------- ^
| ---------- | |
| | | | |
| | blue | | y
| | | | |
| ---------- | |
--------------

In the canvas' constructor I do a set size of the canvas.
Then in the paintcontrol I do a
setBackground(getDisplay().getSystemColor(SWT.COLOR_DARK_BLU E));
I expected the canvas to get filled but the whole tab gets blue filled.

Any help in achieving the above will be greatly appreciated.

regards Chhil
Re: Canvas painting problem in the view of a simple plugin [message #453521 is a reply to message #453453] Thu, 07 April 2005 04:31 Go to previous messageGo to next message
Aaron Siri is currently offline Aaron SiriFriend
Messages: 33
Registered: July 2009
Member
You should check the layout that is being set. I don't know the details
of the example but it is most likely using FillLayout in which case the
size you give to the canvas (the rectangle) will just be ignored. You
could try using a FormLayout instead where you have more control and the
margins could be set.

-Aaron

Chhil wrote:
> Hello,
>
> I am trying to use the simple plugin with a view (eclipse sample plugin
> with a view, by using the new plugin project).
> Removed the table and added a canvas that simply paints the background
> to start off with.
>
> I would like to fix the size of the painted rectangle areas in the view
> tab.
>
> The outer rectangle needs to be white and the inner one needs to be blue
> and their size needs to be fixed through resizing of the windows.
>
> <----x1------>
> -------------- ^
> | ---------- | |
> | | | | |
> | | blue | | y
> | | | | |
> | ---------- | |
> --------------
>
> In the canvas' constructor I do a set size of the canvas.
> Then in the paintcontrol I do a
> setBackground(getDisplay().getSystemColor(SWT.COLOR_DARK_BLU E));
> I expected the canvas to get filled but the whole tab gets blue filled.
>
> Any help in achieving the above will be greatly appreciated.
>
> regards Chhil
Re: Canvas painting problem in the view of a simple plugin [message #453530 is a reply to message #453521] Thu, 07 April 2005 12:16 Go to previous messageGo to next message
Veronika Irvine is currently offline Veronika IrvineFriend
Messages: 1272
Registered: July 2009
Senior Member
A code snippet would help explain what you are trying to do.


"Aaron Siri" <aaron.siri@efi.com> wrote in message
news:d32d98$tea$1@news.eclipse.org...
> You should check the layout that is being set. I don't know the details
> of the example but it is most likely using FillLayout in which case the
> size you give to the canvas (the rectangle) will just be ignored. You
> could try using a FormLayout instead where you have more control and the
> margins could be set.
>
> -Aaron
>
> Chhil wrote:
>> Hello,
>>
>> I am trying to use the simple plugin with a view (eclipse sample plugin
>> with a view, by using the new plugin project).
>> Removed the table and added a canvas that simply paints the background to
>> start off with.
>>
>> I would like to fix the size of the painted rectangle areas in the view
>> tab.
>>
>> The outer rectangle needs to be white and the inner one needs to be blue
>> and their size needs to be fixed through resizing of the windows.
>>
>> <----x1------>
>> -------------- ^
>> | ---------- | |
>> | | | | |
>> | | blue | | y
>> | | | | |
>> | ---------- | |
>> --------------
>>
>> In the canvas' constructor I do a set size of the canvas.
>> Then in the paintcontrol I do a
>> setBackground(getDisplay().getSystemColor(SWT.COLOR_DARK_BLU E));
>> I expected the canvas to get filled but the whole tab gets blue filled.
>>
>> Any help in achieving the above will be greatly appreciated.
>>
>> regards Chhil
Re: Canvas painting problem in the view of a simple plugin [message #453533 is a reply to message #453530] Thu, 07 April 2005 12:45 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: aaa.domain.invalid

Hello,

I am not sure if its a layout thing, after moving the setsize from the
constructor of the canvas to the paint method and all works fine now.

Regards chhil

Veronika Irvine wrote:
> A code snippet would help explain what you are trying to do.
>
>
> "Aaron Siri" <aaron.siri@efi.com> wrote in message
> news:d32d98$tea$1@news.eclipse.org...
>
>>You should check the layout that is being set. I don't know the details
>>of the example but it is most likely using FillLayout in which case the
>>size you give to the canvas (the rectangle) will just be ignored. You
>>could try using a FormLayout instead where you have more control and the
>>margins could be set.
>>
>>-Aaron
>>
>>Chhil wrote:
>>
>>>Hello,
>>>
>>>I am trying to use the simple plugin with a view (eclipse sample plugin
>>>with a view, by using the new plugin project).
>>>Removed the table and added a canvas that simply paints the background to
>>>start off with.
>>>
>>>I would like to fix the size of the painted rectangle areas in the view
>>>tab.
>>>
>>>The outer rectangle needs to be white and the inner one needs to be blue
>>>and their size needs to be fixed through resizing of the windows.
>>>
>>><----x1------>
>>>-------------- ^
>>>| ---------- | |
>>>| | | | |
>>>| | blue | | y
>>>| | | | |
>>>| ---------- | |
>>>--------------
>>>
>>>In the canvas' constructor I do a set size of the canvas.
>>>Then in the paintcontrol I do a
>>> setBackground(getDisplay().getSystemColor(SWT.COLOR_DARK_BLU E));
>>>I expected the canvas to get filled but the whole tab gets blue filled.
>>>
>>>Any help in achieving the above will be greatly appreciated.
>>>
>>>regards Chhil
>
>
>
Re: Canvas painting problem in the view of a simple plugin [message #453582 is a reply to message #453533] Thu, 07 April 2005 15:42 Go to previous messageGo to next message
Veronika Irvine is currently offline Veronika IrvineFriend
Messages: 1272
Registered: July 2009
Senior Member
If the parent of your Canvas has a Layout, you should not be calling
setSize() - ever.

Also, calling setSize and setBackground in the paint is a bad idea. You are
doing way too much work each time you paint - you will make your application
slow and quite possibly make it flash a lot.

If your canvas is inside a layout and you want to create margins around it,
just adjust the margin values as shown below:

public static void main (String [] args) {
Display display = new Display ();
Shell shell = new Shell (display);
FillLayout layout = new FillLayout();
layout.marginWidth = layout.marginHeight = 10;
shell.setLayout(layout);
Canvas c = new Canvas(shell, SWT.NONE);
c.setBackground(display.getSystemColor(SWT.COLOR_BLUE));
shell.open ();
while (!shell.isDisposed ()) {
if (!display.readAndDispatch ()) display.sleep ();
}
display.dispose ();
}

"Chhil" <aaa@domain.invalid> wrote in message
news:d33a93$3cg$1@news.eclipse.org...
> Hello,
>
> I am not sure if its a layout thing, after moving the setsize from the
> constructor of the canvas to the paint method and all works fine now.
>
> Regards chhil
>
> Veronika Irvine wrote:
>> A code snippet would help explain what you are trying to do.
>>
>>
>> "Aaron Siri" <aaron.siri@efi.com> wrote in message
>> news:d32d98$tea$1@news.eclipse.org...
>>
>>>You should check the layout that is being set. I don't know the details
>>>of the example but it is most likely using FillLayout in which case the
>>>size you give to the canvas (the rectangle) will just be ignored. You
>>>could try using a FormLayout instead where you have more control and the
>>>margins could be set.
>>>
>>>-Aaron
>>>
>>>Chhil wrote:
>>>
>>>>Hello,
>>>>
>>>>I am trying to use the simple plugin with a view (eclipse sample plugin
>>>>with a view, by using the new plugin project).
>>>>Removed the table and added a canvas that simply paints the background
>>>>to start off with.
>>>>
>>>>I would like to fix the size of the painted rectangle areas in the view
>>>>tab.
>>>>
>>>>The outer rectangle needs to be white and the inner one needs to be blue
>>>>and their size needs to be fixed through resizing of the windows.
>>>>
>>>><----x1------>
>>>>-------------- ^
>>>>| ---------- | |
>>>>| | | | |
>>>>| | blue | | y
>>>>| | | | |
>>>>| ---------- | |
>>>>--------------
>>>>
>>>>In the canvas' constructor I do a set size of the canvas.
>>>>Then in the paintcontrol I do a
>>>> setBackground(getDisplay().getSystemColor(SWT.COLOR_DARK_BLU E));
>>>>I expected the canvas to get filled but the whole tab gets blue filled.
>>>>
>>>>Any help in achieving the above will be greatly appreciated.
>>>>
>>>>regards Chhil
>>
>>
Extend Canvas or Composite [message #453603 is a reply to message #453582] Fri, 08 April 2005 01:23 Go to previous message
Eclipse UserFriend
Originally posted by: aaa.domain.invalid

Hello Veronika,
You are correct about slowing the app down.
Currently I do not set the layout and all I was doing is the painting
the background in a 640x480 region.
That is all sorted out by sizing and painting the appropriate composites.

If I do a MyCanvas extends Canvas or
MyCanvas extends Composite
I get the desired output but am not sure which one should be used?

Regards Murtuza

Veronika Irvine wrote:
> If the parent of your Canvas has a Layout, you should not be calling
> setSize() - ever.
>
> Also, calling setSize and setBackground in the paint is a bad idea. You are
> doing way too much work each time you paint - you will make your application
> slow and quite possibly make it flash a lot.
>
> If your canvas is inside a layout and you want to create margins around it,
> just adjust the margin values as shown below:
>
> public static void main (String [] args) {
> Display display = new Display ();
> Shell shell = new Shell (display);
> FillLayout layout = new FillLayout();
> layout.marginWidth = layout.marginHeight = 10;
> shell.setLayout(layout);
> Canvas c = new Canvas(shell, SWT.NONE);
> c.setBackground(display.getSystemColor(SWT.COLOR_BLUE));
> shell.open ();
> while (!shell.isDisposed ()) {
> if (!display.readAndDispatch ()) display.sleep ();
> }
> display.dispose ();
> }
>
> "Chhil" <aaa@domain.invalid> wrote in message
> news:d33a93$3cg$1@news.eclipse.org...
>
>>Hello,
>>
>>I am not sure if its a layout thing, after moving the setsize from the
>>constructor of the canvas to the paint method and all works fine now.
>>
>>Regards chhil
>>
>>Veronika Irvine wrote:
>>
>>>A code snippet would help explain what you are trying to do.
>>>
>>>
>>>"Aaron Siri" <aaron.siri@efi.com> wrote in message
>>>news:d32d98$tea$1@news.eclipse.org...
>>>
>>>
>>>>You should check the layout that is being set. I don't know the details
>>>>of the example but it is most likely using FillLayout in which case the
>>>>size you give to the canvas (the rectangle) will just be ignored. You
>>>>could try using a FormLayout instead where you have more control and the
>>>>margins could be set.
>>>>
>>>>-Aaron
>>>>
>>>>Chhil wrote:
>>>>
>>>>
>>>>>Hello,
>>>>>
>>>>>I am trying to use the simple plugin with a view (eclipse sample plugin
>>>>>with a view, by using the new plugin project).
>>>>>Removed the table and added a canvas that simply paints the background
>>>>>to start off with.
>>>>>
>>>>>I would like to fix the size of the painted rectangle areas in the view
>>>>>tab.
>>>>>
>>>>>The outer rectangle needs to be white and the inner one needs to be blue
>>>>>and their size needs to be fixed through resizing of the windows.
>>>>>
>>>>><----x1------>
>>>>>-------------- ^
>>>>>| ---------- | |
>>>>>| | | | |
>>>>>| | blue | | y
>>>>>| | | | |
>>>>>| ---------- | |
>>>>>--------------
>>>>>
>>>>>In the canvas' constructor I do a set size of the canvas.
>>>>>Then in the paintcontrol I do a
>>>>> setBackground(getDisplay().getSystemColor(SWT.COLOR_DARK_BLU E));
>>>>>I expected the canvas to get filled but the whole tab gets blue filled.
>>>>>
>>>>>Any help in achieving the above will be greatly appreciated.
>>>>>
>>>>>regards Chhil
>>>
>>>
>
Previous Topic:Standalone JFace requisites
Next Topic:TreeViewer and LabelProvider
Goto Forum:
  


Current Time: Tue Mar 02 05:51:26 GMT 2021

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

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

Back to the top