Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » GUIDE: how to center a JFace dialog
GUIDE: how to center a JFace dialog [message #458706] Tue, 19 July 2005 17:35 Go to next message
Eclipse UserFriend
Originally posted by: eclipse.vnws.com

Just overloading initializeBounds() method in your class, like this:

protected void initializeBounds()
{
super.initializeBounds();
Shell shell = this.getShell();
Monitor primary = shell.getMonitor();
Rectangle bounds = primary.getBounds ();
Rectangle rect = shell.getBounds ();
int x = bounds.x + (bounds.width - rect.width) / 2;
int y = bounds.y + (bounds.height - rect.height) / 2;
shell.setLocation (x, y);
}

hope it can help :)
Re: GUIDE: how to center a JFace dialog [message #458710 is a reply to message #458706] Tue, 19 July 2005 19:00 Go to previous messageGo to next message
Konstantin Scheglov is currently offline Konstantin ScheglovFriend
Messages: 555
Registered: July 2009
Senior Member
Tan Nhu:

JFace Window already does something like this in:

protected Point getInitialLocation(Point initialSize)

In any case, if you want change location, it is better override this
method, not initializeBounds().

> Just overloading initializeBounds() method in your class, like this:
>
> protected void initializeBounds()
> {
> super.initializeBounds();
> Shell shell = this.getShell();
> Monitor primary = shell.getMonitor();
> Rectangle bounds = primary.getBounds ();
> Rectangle rect = shell.getBounds ();
> int x = bounds.x + (bounds.width - rect.width) / 2;
> int y = bounds.y + (bounds.height - rect.height) / 2;
> shell.setLocation (x, y);
> }
>
> hope it can help :)


Konstantin Scheglov,
Google, Inc.
Re: GUIDE: how to center a JFace dialog [message #458723 is a reply to message #458710] Wed, 20 July 2005 04:06 Go to previous message
Eclipse UserFriend
Originally posted by: eclipse.vnws.com

Konstantin Scheglov:
It seems better :) thank you !


Konstantin Scheglov wrote:
> Tan Nhu:
>
> JFace Window already does something like this in:
>
> protected Point getInitialLocation(Point initialSize)
>
> In any case, if you want change location, it is better override this
> method, not initializeBounds().
>
>> Just overloading initializeBounds() method in your class, like this:
>>
>> protected void initializeBounds()
>> {
>> super.initializeBounds();
>> Shell shell = this.getShell();
>> Monitor primary = shell.getMonitor();
>> Rectangle bounds = primary.getBounds ();
>> Rectangle rect = shell.getBounds ();
>> int x = bounds.x + (bounds.width - rect.width) / 2;
>> int y = bounds.y + (bounds.height - rect.height) / 2;
>> shell.setLocation (x, y);
>> }
>>
>> hope it can help :)
Previous Topic:Problem with SWT_AWT and JOptionPane
Next Topic:MouseEvent in Java Editor
Goto Forum:
  


Current Time: Wed Oct 21 00:13:50 GMT 2020

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

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

Back to the top