954,518 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Getting window size

HI ,
Is it possible to get the window size in Java ,if so cld any 1 guide me....and also i need to fix the windows in a particular position ..how cld i do ds in Java.

Kishorey
Newbie Poster
13 posts since May 2008
Reputation Points: 10
Solved Threads: 0
 

JFrame y = new JFrame("myframe");
y.setBounds(300,400,300,300);

You could try this , the first two variables being for the X and Y position where the frame is put and the next two for the widtha nd heigth..Does this solve your problem??

zyaday
Junior Poster in Training
70 posts since Jun 2008
Reputation Points: 10
Solved Threads: 2
 
Is it possible to get the window size in Java


the getSize() method, amazingly, will do it

JamesCherrill
Posting Genius
Moderator
6,371 posts since Apr 2008
Reputation Points: 2,130
Solved Threads: 1,073
 

To top up what JamesCherrill already said about getting size, to set position you can use methods inherited from Component setLocation(int x,int y) or setLocation(Point p)

peter_budo
Code tags enforcer
Moderator
15,436 posts since Dec 2004
Reputation Points: 2,806
Solved Threads: 902
 

thanks for the response....
but i really need a solution to align the window borders so tat the newly opened windows will not overlap the current window that is running instead their borders have to be aligned so tat i can view both the windows as in Google Desktop Gadgets.Gotta!!!
I need a help in this .

Kishorey
Newbie Poster
13 posts since May 2008
Reputation Points: 10
Solved Threads: 0
 

You've got all you need here. From the position and size you know where the borders are. Try drawing a couple of touching rectangles on a sheet of paper and marking the positions and sizes on them - this should make all the relationships pretty obvious.

JamesCherrill
Posting Genius
Moderator
6,371 posts since Apr 2008
Reputation Points: 2,130
Solved Threads: 1,073
 

hi james,
setLocation gives the location of the window which i'm executing ,so i need the location of the other windows say netbeans i ve opened now so that the netbeans shouldnt overlap the frame or vice versa .,instead it shld align with the frame borders n i shld b able to view both the windows ...
hence i 'm asking how 2 get the location of the netbeans .

Kishorey
Newbie Poster
13 posts since May 2008
Reputation Points: 10
Solved Threads: 0
 

Sorry, I thought both (all) the windows were part of your app. If some of them are not then you will need to get into the Windows/Mac/Linux system apis. Good luck!

JamesCherrill
Posting Genius
Moderator
6,371 posts since Apr 2008
Reputation Points: 2,130
Solved Threads: 1,073
 

ya thanks for ur response....i 'll try

Kishorey
Newbie Poster
13 posts since May 2008
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You