Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Centering a canvas content
Centering a canvas content [message #465311] Thu, 08 December 2005 21:34 Go to next message
Eclipse UserFriend
Originally posted by: igor.dawg.gmail.com

Hi all,
Suppose I draw somthing on a canvas and I need to put it to the center of
it. Is there any way of setting a canvas so everything i draw would
automatically be aligned to the center ???

Thanks in advance

Igor Rohal
Re: Centering a canvas content [message #465319 is a reply to message #465311] Fri, 09 December 2005 01:16 Go to previous messageGo to next message
Daniel Spiewak is currently offline Daniel SpiewakFriend
Messages: 263
Registered: July 2009
Senior Member
That would be a nix. Sorry, but you'll have to center everything manually. It's not terribly hard ('width' and 'height' are the width and height respectively of your content):

Point origin = new Point();

origin.x = (canvas.getSize().x - width) / 2;
origin.y = (canvas.getSize().y - height) / 2;
Re: Centering a canvas content [message #465347 is a reply to message #465319] Fri, 09 December 2005 15:02 Go to previous message
Veronika Irvine is currently offline Veronika IrvineFriend
Messages: 1272
Registered: July 2009
Senior Member
Code should use client area and not size:

Point origin = new Point();

origin.x = (canvas.getClientArea().width - width) / 2;
origin.y = (canvas.getClientArea().height - height) / 2;


"Daniel Spiewak" <djspiewak@gmail.com> wrote in message
news:20447396.1134090992923.JavaMail.root@cp1.javalobby.org...
> That would be a nix. Sorry, but you'll have to center everything
> manually. It's not terribly hard ('width' and 'height' are the width and
> height respectively of your content):
>
>
> Point origin = new Point();
>
> origin.x = (canvas.getSize().x - width) / 2;
> origin.y = (canvas.getSize().y - height) / 2;
> 
Previous Topic:Is there any way to detect a Paste/Cut from within a ModifyListener?
Next Topic:SWT.DLL for Pocket PC
Goto Forum:
  


Current Time: Sat Aug 24 02:11:56 GMT 2019

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

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

Back to the top