How to position Eclipse Dialogs and Messages at ceter of screen.
Posted by sureshkrishna on September 5, 2007
I want to share a common issues that most of the UI programmers come across. When we program with lots of dialogs and messages in any kind of applications, for the usability and predictability we would want most of them to be centered to the screen. In many cases when we use constructors for Dialogs, MessageDialogs, etc… very often we pass newly constructed Shell.
e.g. MessageDialog.openInfo(new Shell(), “Hi This is a test Message Dialog.”);
In the above case remember that we have not specified any of the co-ordinates and often we see that it takes different coordinates depending on the number of times that we invoke it. And each time you invoke, you wonder where the dialog will appear. I have been using a simple solution that solves this issue… Hope some of you will be able to use this code right away. I hope the following code is self explanatory 🙂
I have tested this with all screen resolutions and on Windows XP and OSX.
/**
* All dialogs and messages will be passed with the centered shell.
* @return Shell
*/
public static Shell getScreenCentredShell() {
Display display = PlatformUI.getWorkbench().getDisplay();
Shell centreShell = new Shell(display);
Point size = centreShell.computeSize(-1, -1);
Rectangle screen = display.getMonitors()[0].getBounds();
centreShell.setBounds((screen.width-size.x)/2, (screen.height-size.y)/2, size.x, size.y);
return centreShell;
}
Nicolas Richeton said
Hi,
It’s true that SWT opens windows almost everywhere 🙂
But your code can be disturbing with dual monitor setups, because it always open new windows on the first monitor, even if the application is used on the secondary one.
Because of this, I usually use the bounds of the parent window to compute the coordinates of the new window, and fall back to the bounds of the monitor if there is no parent shell.
I believe most applications behave this way.
Nicolas
Alex Blewitt said
Yeah, this is majorly annoying when I have an Eclipse window on my second screen and it shows up a dialog on the first screen for no good reason.
It will also suck when you’re giving a presentation on how to use Eclipse with an OHP and it suddenly freezes because there’s a modal dialog waiting on your laptop screen that you might not even be able to see from where you’re standing…
Plus, screens aren’t necessarily the same size. Centering it on the active window is a much better idea; and will give centred on the screen when the window is maximised anyway.
sureshkrishna said
Hi Nicolas,
Yes i got the point… i mean if we know the parent shell which is invoking the child, then we are good. Some how i get into some instances where there is no parent shell (true for most of message dialogs).
OK…now i am thinking…do you know how do we get the monitor in which eclipse application is running ? (in a dual monitor system)
~Krishna
Antoine Toulme said
Why not doing simply display.getBounds() ?
It works for me.
How to Get Six Pack Fast said
Hey, nice tips. I’ll buy a bottle of beer to that person from that chat who told me to go to your site 🙂
JFace Dialogs : which one is right for you ? » Sciology said
[…] Positioning Dialogs on Windows […]
Naquaduh said
This will get the center Point for the active shell;
Then simply override the getInitialLocation method of Dialog;
Done.
kioria said
Hi, Naquaduh,
you have an error in your code. Please consider the revised getCenterPoint() method below – without brackets in the second parameter of a Point constructor:
Shell parentShell = PlatformUI.getWorkbench()
.getActiveWorkbenchWindow().getShell();
Rectangle shellBounds = parentShell.getBounds();
rec.setLocation(shellBounds.x + shellBounds.width / 2,
shellBounds.y + shellBounds.height / 2);
With respect, kioria
site said
Wanted to drop a comment and let you know your Feed is not functioning today. I tried adding it to my Yahoo reader account and got nothing.
how to make your own greenhouse fast said
If some one needs to be updated with most recent technologies
after that he must be go to see this web site and be up to date all the time.
original URL said
What’s up to every body, it’s my first go to see of this blog;
this webpage contains remarkable and genuinely fine stuff in favor of visitors.
conair pet clippers said
magnificent put up, very informative. I’m wondering why the opposite specialists of this sector do not notice this. You should proceed your writing. I’m confident, you have a great readers’ base already!
Immigration Advicers in Westminister said
Hi there! Would you mind if I share your blog with my myspace group?
There’s a lot of people that I think would really enjoy your content. Please let me know. Thank you
seo tips said
Does your blog have a contact page? I’m having trouble locating it but, I’d like to shoot
you an e-mail. I’ve got some recommendations for your blog you might be interested in hearing. Either way, great site and I look forward to seeing it expand over time.
car-covers.com said
Wow, marvelous blog format! How lengthy have you been blogging for?
you make blogging glance easy. The full look of
your website is wonderful, let alone the content!
Buy Anti Aging Cream said
I am really delighted to read this webpage posts which includes tons of valuable facts, thanks for providing these information.
Arlene said
There is certainly a great deal to learn about
this topic. I like all the points you’ve made.
energy shots said
Can I simply say what a comfort to find an individual who really knows what they are discussing on the internet.
You actually know how to bring a problem to light and make it important.
More people really need to check this out and understand this side of the story.
It’s surprising you aren’t more popular since you
certainly have the gift.
Voyage said
Bonjour, je suis Danielle
Je suis une fille de vingt-neuf piges j’assume totalement mon age .
Je bosse comme chanteuse ! il apparaît que je suis réservée.
website said
They are also offered in numerous materials
like cooper and brass and like the other manufacturers, but I do not get in the mainstream
as well. The term” cheap garage Sliding Patio Doors, commercial entry systems and industrial access. As these Sliding Patio Doors and windows can be more than 50% corrupt before it will open up, but you should limit the mirror to one of the worst rewards. But this fact is true in Shani Shingnapur, a small seat or a wide bench and a wall cabinet for placing the shower essentials.
laser hair removal stevenage said
Piece of writing writing is also a excitement, if you be
familiar with after that you can write or else it is complicated to write.
quick weight loss said
Outstanding post but I was wanting to know if you could write a litte more on this topic?
I’d be very thankful if you could elaborate a little bit further. Appreciate it!
Maxine said
I am extremely impressed with your writing skills and also with the layout on your weblog.
Is this a paid theme or did you customize it yourself?
Anyway keep up the excellent quality writing, it is
rare to see a nice blog like this one nowadays.
Carrie said
Hello to all, how is everything, I think every one is getting
more from this web site, and your views are good in favor of new viewers.
best free web hosting reviews 2012 said
Hi there, I read your blogs regularly. Your writing style is awesome, keep it
up!
Carri said
Ιf some one needs expert view regarding blogging afterward i recommeոd him/her to pay
a visit this blog, Keep up the fastidious work.
download said
Oh my goodness! Awesome article dude! Many thanks, However I am having
troubles with your RSS. I don’t understand why I can’t join it.
Is there anybody else having the same RSS problems? Anybody who knows the answer can you kindly respond?
Thanks!!
www.dailymotion.com said
First off I would like to say exxcellent blog! I had a quick question
which I’d like to ask if you ddo not mind. I was interested tto find out
how you center yourself annd clear your thoughts
prior tto writing. I have had difficulty clearing my thoughts in gettung
my ideas out there. I do take pleasure in writing but it just seems like the first 10 tto
15 minutes tend too be wasted simply just trying to figure
out how tto begin. Any suggestions orr hints? Cheers!
custom and classic car cleaning said
Attractive section of content. I just stumbled upon your weblog and in accession capital to
assert that I acquire actually enjoyed account your blog
posts. Any way I’ll be subscribing to your feeds and even I achievement you
access consistently quickly.
home click free shipping codes said
We are a group of volunteers and opening a new scheme in our community.
Your site provided us with valuable info to work on. You’ve performed
an impressive task and our whole community shall be
grateful to you.
cheap car hire from aberdeen airport said
Your style is really unique compared to other folks I have read
stuff from. Thanks for posting when you have the opportunity, Guess I’ll just bookmark this page.
get samsung galaxy s2 unlock code free said
A fascinating discussion is worth comment. I do believe
that you ought to write more about this topic, it may nnot be a taboo matter but
typically people do not discuss thesxe topics. To the next!
Cheers!!
root and unlock htc inspire said
That is very fascinating, You’re a very professional blogger.
I have joined your feed and sit up for in quest of extra of your
excellent post. Additionally, I’ve shared your web site in my social networks
xda developers unlock samsung galaxy s2 tmobile said
Hey! I’m at work surfing around your blog from my new apple iphone!
Just wanted to say I love reading through youjr blog and look forward to alll your
posts! Carry on thhe excellent work!
Christen said
Visit to purchase Computer Cuisine Deluxe for $29.
Never use any shortcut methods while cooking, handling
and cleaning cookware unless you are hundred percent sure of its success.
The storage of the pans is far easier when you
may have this potential at your disposal.
how do you unlock a samsung galaxy y said
Nice post. I was checking constantly this blog and I am impressed!
Very helpful info specifically the last section :
) I handle such info much. I used to be looking for this
certain info for a very long time. Thanks and best of
luck.
unlock an htc one x said
Please let me know if you’re looking for a writer for your weblog.
You have some really great posts and I believe I would
be a good asset. If you ever want to take some of
the load off, I’d love to write some articles for your blog in exchange for a
link back to mine. Please send me an email if interested.
Cheers!
unlock htc wildfire orange free said
Terrific work! This is the type of info that are meant to be shared around the internet.
Disgrace on Google for no longer positioning this publish upper!
Come on over and consult with my site . Thanks =)
samsung galaxy note 3 unlocked price said
This is a topic that’s near to my heart…
Many thanks! Exacctly where are your contact details
though?
unlock htc desire orange said
Hello, its fastidious article on the topic of meria print,
we all understand media is a impressive source
of facts.
Minecraft Premium Accounts said
Having read this I believed it was rather informative.
I appreciate you finding the time and energy to
put this article together. I once again find myself personally spending way
too much time both reading and commenting. But so what, it was still
worthwhile!
Daily Movies Online said
Netflix, Blockbuster Online, and Intelliflix are just
a few in the business that can be worth their weight in gold
in the long run. There are plenty of sites on the Internet that
offer links to online movies while other sites allow visitors to rent
them and watch them directly on that site. Of course, you’ve got more options if you’re willing to go a less traditional route
than popcorn.
world star xxx said
The first three months Bollywood suffered a loss of around Rs 200
crore. The i – Phone prank phenomenon is a strange development in the world of i
– Phone applications, but those that actually fake phone calls are definitely one of the top
five unusual uses for the i – Phone. Two issues that were brought up
were the risks involved in unprotected sex.
Imparare a disegnare Manga said
We absolutely love your blog and find almost all of your post’s to be just what I’m
looking for. Does one offer guest writers to write content for you personally?
I wouldn’t mind creating a post or elaborating on most of the subjects you write regarding here.
Again, awesome website!
Isabella said
This is very interesting, You’re a very skilled blogger.
I have joined your feed and look forward to seeking more of your excellent post.
Also, I have shared your site in my social networks!
Ebon Talifarro said
Ebon Talifarro
How to position Eclipse Dialogs and Messages at ceter of screen. « Sciology = Science + Technology
haushalt said
It’s actually a cool and useful piece of information. I’m satisfied that you simply shared this useful info with
us. Please keep us up to date like this. Thanks for sharing.
technology blog 654 said
What blog sites would be good for a small business in floral and gifts?
Sandalay Resort Pattaya Photos said
Sandalay Resort Pattaya Photos
How to position Eclipse Dialogs and Messages at ceter of screen. « Sciology = Science + Technology
95zz9108.Com said
95zz9108.Com
How to position Eclipse Dialogs and Messages at ceter of screen. « Sciology = Science + Technology
omvendt telefonbog said
Thanks for sharing your thoughts about Omvendt mobiltelefonbog.
Regards
software said
Wow, that’s what I was exploring for, what a information!
existing here at this webpage, thanks admin of this
site.