Cynosure.X International LLC

Software: CI Class Package

Tips

Java Programming Tip 1: how to center dialog, frames, and windows on the screen 1/12/1998

Have you ever written an application or applet and wanted to center it on the computer screen dynamically without writing more than 5 lines of code? CI Class Package can ease this task for you with just one line of code! Sound amazing? It is. This feat is accomplished with the Location class. Look at the following example:

Dialog dialog = new Dialog ();
Location l = new Location (dialog.getSize ());
dialog.setLocation (l);
dialog.show ();

Further, if you simply want to make sure your dialog is not outside the screen, you can replace the second line of code above with the following lines:

Point p = new Point (1000, 1000);
Location l = new Location (p, dialog.getSize ());

In the above example, the Location class automatically calculates the screen position for you. It makes sure that the dialog does not extend outside the screen.

Products | Services
Forums | Latest | RSS
Library | Search | Wiki
Help | Licenses

Login | Register

Hacking Digital Cameras
Fun for Photographers



Amazon Associate

Copyright © 1996 - 2024. All Rights Reserved.