🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.swing
Article #10274

Re: Math for centering dialog box inside a main frame

#10274
From: Pascale Leroux
Date: Fri, 22 Oct 1999 00:00
35 lines
1874 bytes
Hiya !

  public void CentrerDialogue() // Center dialog
    {
    Dimension Ecran    = getToolkit().getScreenSize();   // screen size
    Dimension Dialogue = this.getSize(); // dialog size

    setLocation ((Ecran.width - Dialogue.width) / 2, (Ecran.height -
Dialogue.height) / 2);
    }

This center the dialog according to the screen size. If you give the size of
the frame parent, it should work.
Hope this helps, Pascale


Jeff Marendo wrote in message <7upraq$npj6@forums.borland.com>...
>Hello,
>
>I have tried to use what appears to be somewhat of a standard math equation
>for always centering a dialog window (in my case, an 'About' box from the
>Help menu), but the window doesn't appear centered when executed.  It is
>also misaligned if I resize the main window.
>
>Ideally, I'd like to have the 'About' dialog always appear within the
>confines of the window in which it was opened from (and have it be
>completely visible).  I tried basing my algorithm off of the main frame's
>width and height (and the dialog's): it almost centers it, but this is
>pretty much hardcoding it into one spot.  I know I have to use the sizes.
>
>Please advise.  Thanks!
>
>Jeff
>
>
Technical Details
Message-ID: <4D_P3.798$6y2.47179@carnaval.risq.qc.ca>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <7upraq$npj6@forums.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 111d45,869a3aa575acdb31
X-Google-Attributes: gid111d45,public
From: "Pascale Leroux" <DeepCover@videotron.ca>
Subject: Re: Math for centering dialog box inside a main frame
Date: 1999/10/22
Message-ID: <4D_P3.798$6y2.47179@carnaval.risq.qc.ca>
X-Deja-AN: 539279427
References: <7upraq$npj6@forums.borland.com>
X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3612.1700
X-Trace: carnaval.risq.qc.ca 940602944 132.208.210.61 (Fri, 22 Oct 1999 10:35:44 EDT)
Organization: UQAM http://www.uqam.ca/
NNTP-Posting-Date: Fri, 22 Oct 1999 10:35:44 EDT
Newsgroups: borland.public.jbuilder.java.swing