Welcome to Dream.In.Code
Become a Java Expert!

Join 150,171 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 2,284 people online right now. Registration is fast and FREE... Join Now!




application position?

 
Reply to this topicStart new topic

application position?, want to know how to specify WHERE app opens

rwilliamj
23 Aug, 2008 - 07:18 PM
Post #1

New D.I.C Head
*

Joined: 14 Aug, 2008
Posts: 15

hello.
i have recently completed my first real application (thanks pbl). when opened, the gui appears in the upper left corner of the screen. how can i program it to open in a different position (ie. the center) on the screen?
User is offlineProfile CardPM
+Quote Post

thenovices
RE: Application Position?
23 Aug, 2008 - 07:50 PM
Post #2

D.I.C Head
**

Joined: 18 Jan, 2008
Posts: 73



Thanked: 7 times
My Contributions
JFrame has a setBounds method that allows you to set the x- and y-position of the frame when it opens.
User is offlineProfile CardPM
+Quote Post

Unknown Hero
RE: Application Position?
23 Aug, 2008 - 08:28 PM
Post #3

New D.I.C Head
Group Icon

Joined: 4 Sep, 2007
Posts: 44



Thanked: 8 times
Dream Kudos: 50
My Contributions
This is the best way that I've found out for this problem:
CODE

Dimension resolution = Toolkit.getDefaultToolkit().getScreenSize();
JFrame newFrame = new JFrame();
newFrame.setLocation(resolution.width / 3, resolution.height / 5);


On this way, people with any kind of resolution will have your program opened in-the-center-like position. smile.gif

BTW you don't have to use resolution at all. Method .setLocation() has two integers as parameters. You also don't need to divide by 3 and 5 (that's just my "calculation"). smile.gif

This post has been edited by Unknown Hero: 23 Aug, 2008 - 08:29 PM
User is offlineProfile CardPM
+Quote Post

saumya9888
RE: Application Position?
24 Aug, 2008 - 02:42 AM
Post #4

New D.I.C Head
*

Joined: 8 Aug, 2008
Posts: 22


My Contributions
Can't he just use

CODE
setLocationRelativeTo(this);


@Unknown Hero
Works for me but i'm working on NetBeans so what u have stated may have already been stated inside self generated code!!!
User is offlineProfile CardPM
+Quote Post

Unknown Hero
RE: Application Position?
24 Aug, 2008 - 07:10 AM
Post #5

New D.I.C Head
Group Icon

Joined: 4 Sep, 2007
Posts: 44



Thanked: 8 times
Dream Kudos: 50
My Contributions
QUOTE(saumya9888 @ 24 Aug, 2008 - 03:42 AM) *

Can't he just use

CODE
setLocationRelativeTo(this);


@Unknown Hero
Works for me but i'm working on NetBeans so what u have stated may have already been stated inside self generated code!!!


I didn't even know there is such method. smile.gif

I just tried out setLocationRelativeTo() and I got this:
http://img390.imageshack.us/img390/9708/23010367yq3.jpg

The way I use my setLocation() I get this:
http://img92.imageshack.us/img92/2662/75630682pl0.jpg



BTW I don't use NetBeans, just pure Eclipse.
User is offlineProfile CardPM
+Quote Post

rwilliamj
RE: Application Position?
24 Aug, 2008 - 12:42 PM
Post #6

New D.I.C Head
*

Joined: 14 Aug, 2008
Posts: 15

setLocationRelativeTo() works like a charm. absolutely lovely. thank you.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 03:15AM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month