On Thu, 17 Sep 1998 11:23:15 -0400, Jonathan Krebs <jkr...@mtlva.com> wrote:
| Is there any way that I can set the location of Appletviewer on the
| screen from within my applet? The move() method does not do the trick.
The following code works for me:
public void centerOnScreen()
{
if( isApplication() )
{
getJTFrame().centerOnScreen();
}
else
{
Dimension screen = getToolkit().getScreenSize();
Frame f = getTopLevelFrame();
Rectangle bounds = f.getBounds();
f.setLocation( (screen.width - bounds.width) / 2, (screen.height - bounds.height) / 2 );
f.setVisible( true );
f.requestFocus();
}
}
private Frame getTopLevelFrame()
{
Component c = getParent();
System.err.println( "component is " + c + "\n" );
while( c.getParent() != null)
{
c = c.getParent();
System.err.println( "component is " + c + "\n" );
}
if( c instanceof Frame)
{
// Note that this is <b>not</b> the browser window.
return (Frame) c;
}
else
{
return null;
}
}
davep
--
--
Dave Postill Investment Intelligence Systems Corp
Galaxy Support Leader +44 (0)171 628 6960 [voice]
da...@iisc.co.uk [business] +44 (0)171 638 7528 [fax]
dave.p...@pobox.com [personal] http://www.iisc.co.uk