Home > eclipse rcp > Eclipse RCP – Placing shell/dialog in the center or near cursor position

Eclipse RCP – Placing shell/dialog in the center or near cursor position

One of the common requirement in day to day rcp development is to place the dialogs/shells we show in the center of the screen or near to the cursor position.

The following snippet will help you for the same.

Placing at the center of the screen:


Monitor primaryMonitor = display.getPrimaryMonitor ();
Rectangle bounds = primaryMonitor.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);

Placing the shell near cursor:

Point pt = display.getCursorLocation();
 shell.setLocation(pt.x, pt.y);

Happy coding.. 🙂

Advertisements
Categories: eclipse rcp Tags: ,
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: