aspose file tools
The moose likes Swing / AWT / SWT / JFace and the fly likes AWT problem Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT / JFace
Reply Bookmark "AWT problem" Watch "AWT problem" New topic
Author

AWT problem

Metal Zhang
Ranch Hand

Joined: Aug 05, 2001
Posts: 52
Hello!
I created a java.awt.Frame object as the main window of my application.And I also want to create a children window when I click the button in the main window.Ok,I can do that.But I found the children window always appear in the top-left of the screen.
I don't like this appearance.So I want to know how to create a children Window and let it appear as the dimension of the the main Window's client area?
Any advice willbe greatly appreciated!
------------------
Java lover from hell!


Java lover from hell!
Vinod Venugopal
Ranch Hand

Joined: Dec 06, 2000
Posts: 148
You gotto use Toolkit methods to center ur window on the screen, heres some code which could help..call this method when u want to show the window..
public void showCenteredWindow()
{
Frame parent = (Frame)getParent();
Dimension dim = parent.getSize();
Point loc = parent.getLocationOnScreen();
Dimension size = getSize();
loc.x += (dim.width - size.width)/2;
loc.y += (dim.height - size.height)/2;
if (loc.x < 0) loc.x = 0;<br /> if (loc.y < 0) loc.y = 0;<br /> Dimension screen = getToolkit().getScreenSize();<br /> if (size.width > screen.width)<br /> size.width = screen.width;<br /> if (size.height > screen.height)
size.height = screen.height;
if (loc.x + size.width > screen.width)
loc.x = screen.width - size.width;
if (loc.y + size.height > screen.height)
loc.y = screen.height - size.height;
setBounds(loc.x, loc.y, size.width, size.height);
show();
}

- Vinod<br />-------<br />SCJP2
 
 
subject: AWT problem
 
Threads others viewed
How to add a new window on existing one
window position
Splash Window with Prograss bar - PROBLEM
calling second jPanel
how to restrict the focus between parent and child JFrame??
WebSphere development made easy
without the weight of IBM tools
http://www.myeclipseide.com