How to center Dialog over Applet?

A quick question.... When I create a Dialog in an Applet, I have to create a "dummy" frame to be the parent/owner of the Dialog. As a result, when I display the Dialog, it shows up in the upper-left corner of the screen. How do I use a Dialog in an Applet so that it displays centered over the Applet?
Thanks,
Nordman

I have to create a "dummy" frame to be the
parent/owner of the Dialog.No. you do not. You can use the browser frame.
In the applet you can get it like this:
Frame browserFrame;
Component comp= this;
while (! (comp instanceof Frame))
   comp = comp.getParent();
browserFrame = (Frame)comp;you can also use setLocationOnScreen() to set the dialogs position. To set it relative to the applet or the browserFrame, you call getLocationOnScreen on those, and calculate whatever position you want.
Ragnvald Barth
Software engineer

Similar Messages

  • How do you center dialogs with multiple monitors. code, best practices

    My existing code will take the pixel size of the java app, and using the size of the dialog, it will center dialogs perfectly in the center of the application. This is great for single monitors, but when multiple monitors are introduced it is a problem. With dual monitor, the dialog is split in half between the two monitors.
    I should be able to determine which pixel/frame initiated the user's action; and then i am hoping to get some code or direction on:
    1. how to determine which monitor the user initiated the action on (knowing the px or frame location, how would i do this)
    2. how to center dialog on that monitor
    if possible, it would be appreciated if you can provide some code; i cant find anything on determing pixel size of monitors and this seems to be a little bit of a project to do from scratch. open source, 3rd party, insight, guidance, all is appreciated. thanks !

    This code may help:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class OptionPaneDemo {
        ActionListener al = new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                Component comp = (Component) evt.getSource();
                JFrame f = (JFrame) SwingUtilities.windowForComponent(comp);
                showDialogInUpperRightCorner(f);
        public static void main(String[] args) {
            EventQueue.invokeLater(new Runnable(){
                public void run() {
                    new OptionPaneDemo().go();
        void go() {
            GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
            for(GraphicsDevice gd: ge.getScreenDevices()) {
                JButton showDialogButton = new JButton("show the dialog");
                showDialogButton.addActionListener(al);
                JFrame f = new JFrame(gd.getDefaultConfiguration());
                f.getContentPane().add(showDialogButton, BorderLayout.NORTH);
                f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                f.pack();
                centerWindow(f);
                f.setVisible(true);
        void centerWindow(Window w) {
            Rectangle windowBounds = w.getBounds();
            GraphicsConfiguration gc = w.getGraphicsConfiguration();
            Rectangle screenBounds = gc.getBounds();
            int x = screenBounds.x + (screenBounds.width - windowBounds.width)/2;
            int y = screenBounds.y + (screenBounds.height - windowBounds.height)/2;
            w.setLocation(x, y);
        void showDialogInUpperRightCorner(JFrame f) {
            JOptionPane pane = new JOptionPane("Hello, world!");
            JDialog dialog = pane.createDialog(f, "title");
            Rectangle dialogBounds = dialog.getBounds();
            GraphicsConfiguration gc = dialog.getGraphicsConfiguration();
            Rectangle screenBounds = gc.getBounds();
            //int x = screenBounds.x + screenBounds.width - dialogBounds.width;
            //int y = screenBounds.y == 0 ? 1 : screenBounds.y;
            int x = screenBounds.x;
            int y = screenBounds.y + screenBounds.height - dialogBounds.height-1;
            System.out.format("(%d,%d)%n", x, y);
            dialog.setLocation(x, y);
            dialog.setVisible(true);
    }

  • Picture over applet

    Hi there,
    Can somebody please tell me, how I can put a picture (or flash etc.) over Java applet? Whatever I do I always get applet on the surface of the page. Z-index is not working in that case. �Param name=overlay� makes only a little image in the center of the applet. So what to do? Thank you very much in advance!

    hi there, plz reed http://java.sun.com/docs/books/tutorial/uiswing/misc/icon.html#getresource

  • How to tell embedded jinitator applet is still running when window closed

    Hello, we are trying to accomplish the same thing that is mentioned in this post from Metalink. I've searched for a solution and hope someone here can help. Instead of restating the issue I think David Wilson does a good job of explaining what is needed. Can anyone please suggest a possible solution?
    From: David Wilton 07-Oct-05 01:08
    Subject: How to tell embedded jinitator applet is still running when window closed
    How to tell embedded jinitator applet is still running when window closed
    Hi,
    We run an oracle 10g forms application through 9iAS over an intranet. All users are running windows 2000 professional.
    We run separate frame = true but I would like to switch to separate frame = false
    With separate frame = true if the user clicks the outer windows "X" close button (forms mdi window) the user is prompted to save changes before the application ends.
    BUT
    when using separate frame = false
    If the user clicks the upper window "X" button (no longer form mdi window but regular browser window) the window and application is abruptly closed.
    I'm interested in using a onbeforeunload function to confirm if the user wants to close the window. This would be placed in the basejini.htm file. This could always ask if the user wants to exit or not. If they click OK then the window closes but if they click "Cancel" you are returned to the forms application exactly where you left. something like event.returnvalue="do you really want to exit?";
    However if the user exited using the normal exit form method then the applet is already closed before the onbeforeunoad event fires and there is nothing to go back to and I want the window to close automatically. This is accomplished using close.html file in post forms trigger.
    So what I want and what I think many may also want is the check if the embedded applet is still running and if so prompt the user to return to the application or continue to close. Of course If the applet is no longer running then just close because there is no reason confirm closing anymore.
    Does anyone have a html/JavaScript solution that can be placed in the jinitiator.htm file? or similar?
    Thank you
    David
    [email protected]
    From: Andrew Lenton 07-Oct-05 08:58
    Subject: Re : How to tell embedded jinitator applet is still running when window closed
    I don't know if this is exactly what you are after but you can add the following to the top of your basejini.htm file and it should prompt the user before exiting the IE window.
    <BODY %HTMLbodyAttrs%>
    %HTMLbeforeForm%
    <SCRIPT>
    <!--
    window.onbeforeunload = unloadApplet;
    function unloadApplet(){
    message = "Warning! Please exit the Java Applet prior to
    exiting the browser"
    return message;
    //-->
    </SCRIPT>
    From: Oracle, mohammed pasha 07-Oct-05 09:55
    Subject: Re : How to tell embedded jinitator applet is still running when window closed
    David,
    Well I could not understand your complete requirement.
    Refer to Note.201481.1 How to Close the Browser Window When Closing Forms And How to Simulate SeparateFrame By Javascript
    Note.115905.1 How to Close Browser Window When Closing Webforms Applet
    Kind Regards,
    Anwar
    From: David Wilton 07-Oct-05 14:37
    Subject: Re : How to tell embedded jinitator applet is still running when window closed
    Thank you for your reply and yes you did not understand my question fully.
    Sorry if this is a long reply
    I am able to close the browser window using information in notes 115905.1 and 201481.1, this is not the issue. We implemented this several years ago. It is workable for both separate frame = true or false.
    It is most important to not allow the user to end their forms application by closing the windows browser, they must close using normal form exit commands.
    What I want is to have separate frame = false, the big drawback to this option is the user can exit the application and bypass all forms code by pressing the windows "X" close button. This is why we need the code as just provided by Andrew Lenton above in this thread.
    BUT Andrew's code will always prompt the user before closing the window and I do not want that. I want the user to be prompted only under scenario 2 listed below.
    Here's the 2 case scenario for exiting the application.
    1. If the user closes properly and uses exit form which fires all normal form triggers including post_form with it's call to close.html file.
    All uncommitted changes are saved or rollback and the users session is ended normally both on the database and in the application server.
    All browser windows will close, great all is good. And without Andrew's code the window will close but with Andrew's code the user will be prompted to close or not, if they select Cancel the window will remain but the applet has already ended so why prompt? ...This is what I want to avoid.
    2. In the forms app. if the user clicks the windows "X" close button with uncommitted changes. The browser just closes the changes are rollback without prompting the user to save. The users sessions are now lost and still running in the database and application server until they are timed out.
    If I use Andrew's code then the user will be prompted to continue to close or go back, if they click Cancel to go back then focus returns to the forms application and the user can continue to work. If the user clicks OK then the window closes and unfortunately their sessions are still lost until timed out.
    So what I desire is to add to Andrew's code to check if the embedded applet is still running and prompt the user to close or not accordingly.
    Something like:
    Basejini.htm like
    </HEAD>
    <SCRIPT LANGUAGE="JavaScript">
    function maximizeWindow()
    window.moveTo(0,0);
    window.resizeTo(screen.availWidth,screen.availHeight);
    function confirm(){
    If(document.embeddedapplet.closed())
    Win.opener = self;
    win.close();
    Else if
    event.returnValue = "Closing Forms Application. OK to continue?";
    </SCRIPT>
    <BODY %HTMLbodyAttrs%, onload="maximizeWindow()", onbeforeunload="confirm()">
    %HTMLbeforeForm%
    I hope this explains my requirements.
    David
    From: Oracle, Evelene Raechel 10-Oct-05 06:45
    Subject: Re : How to tell embedded jinitator applet is still running when window closed
    Hi,
    Note.199928.1 How to Alert User on Closing Client's Browser Window in Webforms
    Regards,
    Rachel
    From: David Wilton 11-Oct-05 17:40
    Subject: Re : How to tell embedded jinitator applet is still running when window closed
    I'm sorry this is not helpful at all.
    Note 199928.1 is only an alert which does not stop the closing of the window and still displays as an alert if the user does close properly using exit form ... so why would you want to display the alert then?
    This is exaclty what I do not want and why I want to determine if the applet is still running before displaying any kind of message.
    David
    From: Oracle, Evelene Raechel 17-Oct-05 12:23
    Subject: Re : How to tell embedded jinitator applet is still running when window closed
    Closing thread.
    Thanks,

    Hello,
    I had the same issue last year - wanting to provide a warning on closing the browser, but only if the Forms session is still running. The approach I took is described below, see also the thread where I originally posted this at Closing brower window
    Hi there,I've had a similar requirement - or rather, the two conflicting requirements: to warn when the browser is being closed, but for the app to be able to close the browser without a warning being fired.
    To always provide a warning when someone (the user or the Forms app) tries to go to a different page (e.g. your close.htm), use Javascript like:
    function confirmExit(){
    if(appletRunning==true) {
    msg="Closing this window or navigating to another page will end your SomeGreatApp session.";
    window.event.returnValue=msg;
    And make a call to confirmExit() in the onBeforeUnload event of your main page.
    You'll notice I first check an 'appletRunning' variable before displaying the warning. This Javascript variable is set to true by my app when it starts up, using an embedded Javabean that calls out to Javascript. Once that variable is set to true, then the warning will be displayed if the user tries to shut the browser by clicking on the 'x' button, or to go to a different URL.
    When my app is shutting down, it uses the same Javabean to set appletRunning back to false. It then navigates to a close.htm - which will be done without a warning being displayed.
    See Re: How can a Javabean call Javascript function of the basejpi.html?? for example code on how to call Javascript from a bean embedded in your Forms app.
    Hope these ideas help you out, it's worked for me (so far, anyway!!)
    James

  • How do I integrate Java Applet and JavaScript?

    Hi:
    This has been asked before, I have read the archives, yet I'm still left with some doubts, and some posts are VERY old and may not apply today. (sorry, some questions might seem stupid, this is my first applet). The purpose is to create a light weight application for managing certificates stored on a smart card, requesting certificate renewal from a server and installing the issued certificate on the card.
    I need to create an applet (signed) to bridge the gab caused by the security limitations of JavaScript in order to access the smart card on the client. The applet will manage certificates on the card and do client-card interaction, while all client-server and user interaction is done by AJAX/JavaScript.
    So, the applet is actually supposed to be an invisible object embedded on the page that is accessed by the JavaScript. How do I go about this?
    - is there any reason to prefer JApplet over Applet?
    - do the JavaScript need to invoke start() or init() or is this done on page load?
    - are there limitations on data exchange with the applet (ie. only string types)?
    - how do I throw exceptions from the applet to the calling script?
    and: will is it better to let JavaScript do all http to keep the applet light, or to let the applet fetch files given a URL (to fetch the new certificate)?
    If the applet is stored in a jar-file, how do I indicate which class/method to invoke? Do the JavaScript have access to public methods only?
    Thanks for your advice and suggestions,
    Erik

    Hi,
    Are you still interested?
    I can work with you over this.
    Adil

  • How to center menu and add spacing between buttons?

    Here is my site: http://lauraportfolio.hostoi.com/index.html (If you are using Google Chrome you can right click and select "view page source" to see the html of the page)
    See how the menu button are justified the left of the light pink menu bar? How can I put them in the center?
    I would like to know how to center the menu, and then add spacing between the buttons.
    At one point I added spacing between the buttons using CSS padding, but when I did that the last menu button, "Graphics" ran off the pink menu bar and became invisible and all kinds of crazy ugly stuff!
    Below is what I beleive to be all of the CSS styling for the menu:
    #menubar
              width: 900px;
              height: 72px;
              padding: 0;
              background-color: transparent;
              background-image: url(transparentpink.png);
              background-repeat: repeat;
    ul#menu, ul#menu li
    { float: left;
      margin: 0;
      padding: 0;}
    ul#menu li
              list-style: none;
              padding-right: 0px;
              padding-left: 0px;
              margin-right: auto;
              margin-left: auto;
    ul#menu li a
              letter-spacing: 0.1em;
              display: block;
              float: left;
              height: 37px;
              text-align: center;
              color: #f0dbca;
              text-transform: none;
              text-decoration: none;
              background: transparent;
              font-family: bonvenoCF, verdana, Geneva, sans-serif;
              font-size: 150%;
              font-style: normal;
              font-weight: normal;
              font-variant: normal;
              padding-top: 29px;
              padding-right: 26px;
              padding-bottom: 6px;
              padding-left: 26px;
    ul#menu li a:hover, ul#menu li.selected a, ul#menu li.selected a:hover
              color: #F0DBCA;
              background-color: #F1836A;

    PART 1
    So as long as the width of the buttons plus the padding doesn't go over 900px it won't run off the page?
    Right.   The "box model" in CSS works like this:
    width + padding + border = actual visible/rendered width of box
    height + padding + border = actual visible/rendered height of box.
    PART 2
    And do you know how I can center the whole thin instead of it being left-aligned on the menu bar?
    You can't center floated menu items.  The best you can do is make your menu fit the entire width of the container (or as close as you can) as described in PART 1 above. 
    To center your #menu container, use margin:0 auto;
    To center text, use text-align:center on the #menu li a.
    Nancy O.

  • How do I get Java Applets working on FF4 Mac?

    My website's photo upload applet uses Java to upload, and ever since FF4 beta releases, all the way up to the final, I get a missing plugin error. This error is ONLY on FF, it works on chrome and safari.
    Screenshot:
    http://img23.imageshack.us/i/javad.png/
    Clicking manual install goes to:
    http://www.oracle.com/technetwork/java/javase/download-138376.html
    So in other words, the manual install is pointless.
    How can I get these applets working?

    PS. I'm downgrading till this is fixed. FF4 is useless to me without this ability. I always liked FF for the better upload ability over Safari and Chrome, so I'd love to be able to use it. :-)

  • Center dialogs with IE (java plugin 1.3.0_02 or higher)

    Hello,
    Has anyone successfully centered a modal dialog over the applet running inside a browser? If so would you be willing to share your code with me and the rest of us?
    I had one solution but it seems to cause problems starting with jdk1.3.0_02 (it involved using JOptionPane.createDialog). Really ugly solution but it worked.
    TIA.
    Tom Varghese
    [email protected]

    If my sample code for your other post helps, I want these duke dollars too :)

  • How do I start over with my mac book pro

    I used disk utility and found my hard drive to be corrupt. How do I start over and clean this up?

    Backup your Users data off the computer to regular storage drive (not TimeMachine), hold c boot off the 10.6 and use Disk Utility to Erase with Zero the entire drive of everything, this will map off any bad sectors and if you have enough spares, the drive shoudl work fine again.
    Reinstall OS X, setup with the same user name, Software Update until clear, install your programs from fresh sources and return files from the storage drive, don't use TM to restore it's also corrupted image, just have to start all over again.
    Read more, especially the section about bad sectors
    https://discussions.apple.com/docs/DOC-3044
    https://discussions.apple.com/docs/DOC-3045
    https://discussions.apple.com/docs/DOC-3046
    https://discussions.apple.com/docs/DOC-3172
    https://discussions.apple.com/community/notebooks/macbook_pro?view=documents

  • I have purchased my first smart phone. iphone 5. I want to use sounds sent to me in text messages as ringtones but don't know how to move them over. Any help would be appreciated.

    I have purchased my first smart phone, an iphone 5.  I would like to use some of the sounds from text messages for ringtones but don't know how to move them over.   Any help would be appericated.

    I'm sorry, had you already pointed out the rules which stated that lines from 2 separate accounts were eligible??? I don't see anywhere in the advertisement specifically stating that lines from 2 separate accounts would be eligible, so THAT is not what's advertised, either.
    As far as I know Verizon's BOGO offers have ALWAYS been for lines on the same account. Possibly someone could chime in where they have received this offer on 2 separate accounts? The ONLY exception to this was someone getting the offer with 2 eligible lines on their account, reactivating the old phone on one of the lines and then giving one of the new phones to someone on another account.
    Sorry if you think simply because someone disagrees with you, they are being condescending. That is certainly not the case. Good luck.

  • I have to create a new iTunes account as I cannot remember the security question answers to my current account, how do I move over my purchases from my current account to my new account?

    I have to create a new iTunes account as I cannot remember the security question answers to my current account, how do I move over my purchases from my current account to my new account?

    fayry wrote:
    ... how do I move over my purchases from my current account to my new account?
    This is not possible...
    Anything Downloaded with a Particular Apple ID is tied to that Apple ID and Cannot be Merged or Transferred to a Different Apple ID.
    Apple ID FAQs  >  http://support.apple.com/kb/HE37

  • HT1382 How can I copy over my contact list from my ipod touch 3 to my new ipod touch 5 ?

    How can I copy over my contact list from my ipod touch 3 to my new ipod touch 5 ??

    Sync it with iTunes on your computer.

  • How to lmplement table in applet

    hi friends
    im not known how to implement table in applet using " java.applet.* " class
    plz reply as soon as possible..

    friend
    my project is implemented in applet but as u suggest
    for Jtable concept then my project is workingSo you have a JTable and it works? What are you asking then?
    What is your applet built with AWT, Swing, something else?

  • HT4889 Replacing System hard drive with a new one. How to get everything over to the new boot drive?

    Replacing System hard drive with a new one. How to get everything over to the new boot drive? Should I use Carbon Copy or does apple have a better untility to do this?
    I can't get my current system drive (OSX 10.8.3) to start on the first try. I always have to shut down and restart again to finally see the Apple logo.
    Have used disc utility to repair the disc and permissions several times and that works. The next time I boot up, it works fine and I get the apple logo, but then the second time I boot up, it's back to the blank screen again and it only boots after the second try.  I have tried this repair three different times now always with the same result. Works right the first try (after the repair) then from the second time on it doesn't work. I just get the white screen until I reboot a second time.
    Thinking I should change drives but what's the easist and best way to move everything over to the new drive so it will boot correctly with all my data on it. This is the system drive for a Pro Tools 10HD setup. MacPro 3,1 with 16 gigs ram and OSX10.8.3 on it.
    Thanks for any help!

    If you have a time machine back up of your current drive you can do this
    Shut down your computer, install the new drive. While the computer is off plug in the external hard drive that you have your time machine back up on. Hold Option key while the computer turnes on, let go of the option key once you get a grey screen. Shortly after you'll see  a list of bootable drives, select the one that has your time machine back up on it and boot into that drive.
    From there go into disk utility, format your new drive too, osx extended journaled ( I think, double check that, its been awhile since ive had to do this), hit format
    Exit disk utility and then you can use time machine to copy all your exisit data to the new hhd and then your pretty much done.
    There is also a program called Carbon Cloner that will do esentially the same thing however I've never uesed it.

  • How do I make an Applet read a file on my web host?

    How do I make an Applet read a file on my web host?
    I am wanting to put a file on my web host that has usernames and user details and other stuff on it...
    I was wondering whether anyone knows how to make the Applet open a file on my webserver, check if the username exists, if not add to the file the username and details?
    thanks

    URL myURL = new URL(getDocumentBase(), filename);
    InputStream myInputStream = myURL.openStream();
    DataInputStream dis = new DataInputStream(myInputStream);
    String oneLine = dis.readLine();
    Use output stream for writing..
    hope this works !!!

Maybe you are looking for

  • Is there a way to rotate images in iPhoto on the ipad

    I take photos with the iPhone or iPad and unless I sync them back to the Mac, there does not seem to be a way to rotate images. This makes having a nice slideshow (for the unlock screen) a problem as a bunch of images are all sideways. I'd like to be

  • How do I restore my iMac with no backup after it was erased through iCloud find my iMac

    I removed my iMac from my device settings on my iCloud on accident. I had bought a new one for my office and moved this one to my home for my wife. Well, I set it up for her, did the migration from her old computer to her new computer. Worked like a

  • Tablespace file in Oracle 10.2.0.4.0  twice as large as in 9.2.0.7

    The tablespace file of an database schema in oracle 10 is twice the size of the same database schema in oracle 9( 16.4 GB versus 8.11GB ) At first I thought it was due to the charachtersets used, but these are in both the versions the same, in oracle

  • No sound for some items, sound for others

    my powerbook can play sound in terms of a DVD or CD or MP3, but cannot play sounds (ends up muted) embedded on webpages or in a video game. suggestions?

  • ABAP Proxy on XI System itself?

    Hi all! I was wondering whether it is possible to use an ABAP Inbound Proxy that is located on the XI system itself (e.g. for getting some additional data out of the SAP database as you would do via RFC function modules)? How does the XI react if it