This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Murach's Python Programming and have Michael Urban and Joel Murach on-line!
See this thread for details.
Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

AWT problem  RSS feed

 
Metal Zhang
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Vinod Venugopal
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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();
}
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!