Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Moving Appletviewer

0 views
Skip to first unread message

Jonathan Krebs

unread,
Sep 17, 1998, 3:00:00 AM9/17/98
to
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.


Dave Postill

unread,
Sep 18, 1998, 3:00:00 AM9/18/98
to
[This followup was posted to comp.lang.java.gui and a courtesy copy was sent to the cited author,
Jonathan Krebs]

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

0 new messages