Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

centering applications 1

Status
Not open for further replies.

GIGN

Programmer
Oct 6, 2000
1,082
0
0
NZ
Curiously, when JBuilder centers a Frame, the code has no mention of it, I cannot find how they do it. So how can I get screenWidth? ;-)
b[sup]2[/sup] - benbiddington@surf4nix.com
 
Hi.

Do like this :

import java.awt.*;
...
Dimension screenDim =
Toolkit.getDefaultToolkit().getScreenSize();
...
int scrWidth = screenDim.width;
...

Bye. --
Globos
 
primo man, thanks --;-)
b[sup]2[/sup] - benbiddington@surf4nix.com
 
Here is a little piece of code which works great for me.

//Center the window
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();

Dimension frameSize = this.getSize();
if (frameSize.height > screenSize.height) // make sure frame fits
frameSize.height = screenSize.height; // on screen.
if (frameSize.width > screenSize.width)
frameSize.width = screenSize.width;
this.setLocation((screenSize.width - frameSize.width) / 2,
(screenSize.height - frameSize.height) / 2);
 
Oh, I got the last post; thanks ;-)
b[sup]2[/sup] - benbiddington@surf4nix.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top