Locating a JDialog in a JApplet

My applet displays a JDialog object but, I can't locate the dialog at the center of the applet. Here is what I do:
// this is call from the applet.
MyDialog dialog = new MyDialog(this);
// this is the constructor for my dialog
MyDialog(JApplet owner) {
  super(owner,"Hello...",true);  // the compiler doesn't accept a JApplet, a Component nor any other type of object I try.
}I have also tried to call the dialogs setLocation() method. The trouble here is that I can't find the center of the applet. I hope you can point my nose in the right direction.
Thanks.

If you pass the Applet as the parent, you will find a problem with your Dialog if you bring up another application window over the browser window while the Dialog is visible: on refocusing the browser window, the Dialog will still have the focus but will be hidden behind the browser window.
Use the following to get a Frame for a Dialog. This prevents the above from happening and ensure the Dialog will always be centred over the applet:
     public Frame getDialogFrame()
          /* CREATES AND POSITIONS A FRAME USED BY DIALOGS
             TO ENSURE THAT DIALOG MODAL AND CENTRED OVER APPLET*/
          Object parent = this.getParent();
          while(!(parent instanceof Frame)) parent=((Component)parent).getParent();
          Frame dialogFrame = (Frame) parent;
          Point p = this.getLocationOnScreen();
          dialogFrame.setLocation(p.x, p.y);
          return dialogFrame;
     }

Similar Messages

  • Set location of JDialog

    How to set the location of JDialog?
    I have set the parent of the JDialog, but it still appears at the top left corner of the screen.
    public MyDialog extends JDialog{
    public MyDialog(JDialog parent, boolean modal) {
    super(parent,"Open existing database",true);
    Can someone help me... Thx :)

    in your MyDialog:
    setLocationRelativeTo(parent);
    .....or somewhere else:
    MyDialog myDialog = new MyDialog(parent, modal);
    myDialog.setLocationRelativeTo(parent);

  • Open a JDialog from an JApplet

    Hello,
    I have an applet and I want to open a separate window. The problem is that I want this window to be modal, and therefore I have to use a JDialog, but a JDialog needs an owner that can only be a JFrame or a JDialog, so I cannot use the JApplet as an owner. I tried to set the owner to null, but then if the user changes the focus to another window in his/her OS, and then returns to the browser, the JDialog does not reappear, so the applet is stuck!
    Does anybody have an idea how I can solve this problem?
    Thanks very much.

    Yes, cuz all applets have a frame....
    Frame f =
    (Frame)SwingUtilities.getAncestorOfClass(Frame.class,
    this);Thank you very much. I will try this solution.

  • Problem displaying JDialog from a JApplet

    When I try to display a JDialog (of a JFrame) from a JApplet, the dialog is displayed but it never receives any paint events, so the form seems empty.
    Basically, this is what happens:
    A JPanel is added to the content pane of a JApplet.
    When that panel receives a mouse action event, a new window is created like this:
    TestWindow tw = new TestWindow();
    tw.setVisible();That's it. When the window is started from a method in the applet itself, however (init() for example) the window does display correctly.
    Can anyone tell me what might be going wrong?

    /*  <applet code="AppletDialog" width="300" height="180"></applet>
    *  use: >appletviewer AppletDialog.java
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class AppletDialog extends JApplet
        JDialog dialog;
        public void init()
            initDialog();
            getContentPane().setLayout(new BorderLayout());
            getContentPane().add(getNorthPanel(), "North");
            getContentPane().add(getSouthPanel(), "South");
        private void initDialog()
            JLabel label = new JLabel("dialog contents", JLabel.CENTER);
            dialog = new JDialog(new Frame(), false);
            dialog.getContentPane().add(label);
            dialog.setSize(200,100);
            dialog.setLocation(540,200);
        private JPanel getNorthPanel()
            JButton launch = new JButton("show dialog");
            launch.addActionListener(new ActionListener()
                public void actionPerformed(ActionEvent e)
                    dialog.setTitle("from button");
                    dialog.setVisible(true);
            JPanel panel = new JPanel();
            panel.add(launch);
            return panel;
        private JPanel getSouthPanel()
            JPanel panel = new JPanel(new BorderLayout());
            panel.setBackground(Color.pink);
            panel.add(new JLabel("click here for dialog", JLabel.CENTER));
            Dimension d = panel.getPreferredSize();
            d.height = 45;
            panel.setPreferredSize(d);
            panel.addMouseListener(new MouseAdapter()
                public void mousePressed(MouseEvent e)
                    dialog.setTitle("from mouse");
                    dialog.setVisible(true);
            return panel;
        public static void main(String[] args)
            JApplet applet = new AppletDialog();
            JFrame f = new JFrame();
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.getContentPane().add(applet);
            f.setSize(300,180);
            f.setLocation(200,200);
            applet.init();
            f.setVisible(true);
    }

  • How to set a Japplet as parent for a JDialog ?

    Hi,
    I am using netbeans IDE 6.0 for swing development. I have a web application where i have main GUI as JApplet, In this I am calling a custom JDialog on a button click.
    Code for main GUI looks like,
    import javax.swing.*;
    import javax.swing.event.*;
    import java.awt.*;
    import java.awt.event.*;
    public class Demo extends JApplet implements ActionListener {
        JButton btn = new JButton();
        String msg;
        public void init(){
            add(btn);
            this.setBounds(200, 200, 200, 250);
            this.setVisible(true);
            btn.setText("Click");
            msg = "This is test message";
            btn.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    MyDialog diag = new MyDialog(msg);
                    diag.setVisible(true);
         public void actionPerformed(ActionEvent arg0) {
    }The following code is for custom dialog. Here super(parent,modal) is commented as how don't know how to pass JApplet as container for JDialog.
    public class MyDialog extends javax.swing.JDialog {
        /** Creates new form MyDialog */
        public MyDialog(String msg) {
            //super(parent, modal);
            initComponents();
            jTextArea1.setText(msg);
        /** This method is called from within the constructor to
         * initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
        private void initComponents() {
            Jlbl = new javax.swing.JLabel();
            jScrollPane1 = new javax.swing.JScrollPane();
            jTextArea1 = new javax.swing.JTextArea();
            jButton1 = new javax.swing.JButton();
            addWindowListener(new java.awt.event.WindowAdapter() {
                public void windowClosing(java.awt.event.WindowEvent evt) {
                    closeDialog(evt);
            Jlbl.setText("Text");
            add(Jlbl, java.awt.BorderLayout.NORTH);
            jTextArea1.setColumns(20);
            jTextArea1.setRows(5);
            jScrollPane1.setViewportView(jTextArea1);
            add(jScrollPane1, java.awt.BorderLayout.CENTER);
            jButton1.setText("ok");
            jButton1.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jButton1ActionPerformed(evt);
            add(jButton1, java.awt.BorderLayout.SOUTH);
            pack();
        /** Closes the dialog */
        private void closeDialog(java.awt.event.WindowEvent evt) {                           
            setVisible(false);
            dispose();
        private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                       
            setVisible(false);
            dispose();
        // Variables declaration - do not modify                   
        private javax.swing.JLabel Jlbl;
        private javax.swing.JButton jButton1;
        private javax.swing.JScrollPane jScrollPane1;
        private javax.swing.JTextArea jTextArea1;
        // End of variables declaration                 
    }My problem is that how can i set main window that is JApplet as parent to JDialog so that it should reside inside main window.
    Any suggestion would be helpfull.
    Thank you in advance.

    hi,
    I Got solution from following ;
    [Open a JDialog from an JApplet|http://forums.sun.com/thread.jspa?forumID=31&threadID=654054]
    But when I open the applet in browser and click button from applet to create JDialog, the dialog shown can be moved out side browser window (applet window). how is this happening ?
    Your suggestion would definitely help.
    Thank you

  • JDialog and JApplet

    Can i use a JDialog with a JApplet? When someone hits a button in the applet's GUI a JDialog must appear?
    How can this be achieved?

    [url http://java.sun.com/docs/books/tutorial/uiswing/components/dialog.html]How to Use Dialogs

  • Is there a way to display a  non modal JDialog on JApplet

    Whenever I try to add a non modal JDialog over a JApplet, the JDialog freezes and components on it never gets painted. After a disappointing search over web, I've kinda begin to hate swing. I am shocked that a very basic thing like this is so hard to achieve in Java. Any solution folks?
    My code is as follows:
    import java.awt.Frame;
    import javax.swing.JApplet;
    import javax.swing.JDialog;
    import javax.swing.JLabel;
    import javax.swing.JButton;
    public class DialogApplet extends JApplet {
         private javax.swing.JPanel jContentPane = null;
         private JButton jButton = null;
          * This method initializes jButton     
          * @return javax.swing.JButton     
         private JButton getJButton() {
              if (jButton == null) {
                   try {
                        jButton = new JButton();
                        jButton.setText("Click Me"); 
                        jButton.setBounds(75, 80, 147, 34); 
                        jButton.addActionListener(new java.awt.event.ActionListener() {
                             public void actionPerformed(java.awt.event.ActionEvent e) {   
                                  Frame f = javax.swing.JOptionPane.getFrameForComponent(jContentPane);
                                  JDialog pi = new JDialog(f, "MainFrame Dialog", false);
                                pi.getContentPane().add(new JLabel("I got to be working Bossie!!!"));
                                pi.pack();
                                pi.setLocation(75, 80);
                                pi.setVisible(true);
                                try {
                                Thread.sleep(10000);
                            } catch (InterruptedException e1) {
                                e1.printStackTrace();
                                pi.setVisible(false);
                   catch (java.lang.Throwable e) {
                        e.printStackTrace();
              return jButton;
         public static void main(String[] args) {
          * This is the default constructor
         public DialogApplet() {
              super();
              init();
          * This method initializes this
          * @return void
         public void init() {
              this.setSize(300,200);
              this.setContentPane(getJContentPane());
          * This method initializes jContentPane
          * @return javax.swing.JPanel
         private javax.swing.JPanel getJContentPane() {
              if(jContentPane == null) {
                   jContentPane = new javax.swing.JPanel();
                   jContentPane.setLayout(null);
                   jContentPane.add(getJButton(), null); 
              return jContentPane;
    }

    try this, it is really simple, just to look at
    example from the swing tutorials.
    Thanks my friend, If you carefully observe my code, I also needed some piece of code to run in the background ((The thread.sleep() part)) while displaying the dialog. The problem was the JDialog used to freeze and components on it never used to get painted. Finally I managed to find a way out. If we try to display a JDialog with a new thread, The event dispatching thread takes precedence and the painting of components on the JDialog happens only after even dispatching thread is done. All I did was display JDialog in the event dispatch thread and run the background process in new thread.
    My code.
    import java.awt.BorderLayout;
    import java.awt.Container;
    import java.awt.Frame;
    import javax.swing.JApplet;
    import javax.swing.JButton;
    import javax.swing.JDialog;
    import javax.swing.JLabel;
    import javax.swing.JOptionPane;
    import javax.swing.JPanel;
    public class DialogApplet extends JApplet {
        private javax.swing.JPanel jContentPane = null;
        private JButton jButton = null;
        private JDialog dialog = null;
         * This is the default constructor
        public DialogApplet() {
            super();
            init();
         * This method initializes this
        public void init() {
            this.setSize(300, 200);
            Container container = this.getContentPane();
            container.add(getJContentPane());
         * This method initializes jContentPane
         * @return javax.swing.JPanel
        private javax.swing.JPanel getJContentPane() {
            if (jContentPane == null) {
                jContentPane = new javax.swing.JPanel();
                jContentPane.setLayout(null);
                jContentPane.add(getJButton(), null);
            return jContentPane;
         * This method initializes jButton
         * @return javax.swing.JButton
        private JButton getJButton() {
            if (jButton == null) {
                try {
                    jButton = new JButton();
                    jButton.setText("Click Me");
                    jButton.setBounds(75, 80, 147, 34);
                    jButton.addActionListener(new java.awt.event.ActionListener() {
                            public void actionPerformed(java.awt.event.ActionEvent e) {
                                showDialog();
                } catch (java.lang.Throwable e) {
                    e.printStackTrace();
            return jButton;
         * This method displays Dialog
        public void showDialog() {
            final Frame frame = JOptionPane.getFrameForComponent(this);
            dialog = new JDialog(frame, "DialogApplet", false);
            dialog.setModal(true);
            Container contentPane = dialog.getContentPane();
            JPanel panel = new JPanel(new BorderLayout());
            panel.add(new JLabel("I got to be working Bossie!!!"), BorderLayout.CENTER);
            contentPane.add(panel);
            dialog.pack();
            Thread t = new Thread() {
                    public void run() {
                        for (int i = 0; i < 100000; ++i) {
                            System.out.println(i);
                        dialog.hide();
            t.start();
            dialog.show();
    }

  • Problem with setLocation in a multi screen environment

    hello,
    I'm using a multiple screen environment (matrox graphicccard, 3 screens).
    I've a application moving some JDialogs to screen-locations saved somewhen before. So far so good.
    getLocation () for my left screen delivers me a negative value:
    e.g. getLocation().x = -150
    getLocation().y = 50
    setLocation (-150, 50) works as expected.
    Ok, but if I use the same application on another workstation using another matrox driver, the dialog disappears.
    On my computer the 3 screens are handled as separate screens (the one in the middle as the mainscreen) => 3x1024x768
    JDialogs on the left screen are given negative x-location values, JDialogs on the right screen have x-location values greater than 1024.
    On the other computer the 3 screens are handled as one big desktop => 1x3072x1024 (as said: other matrox device).
    My problem is now: if I transfer my locations stored in an external config-file somewhere else I can't restore the location on the other computer, seems clearly there is no negative screen with this graphiccard.
    I tried following code
         public void setLocation (int x, int y)  {
              GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
              Dimension screenSize;
              try  {
                   Rectangle screenS = new Rectangle ();
                   GraphicsDevice[] gs = ge.getScreenDevices ();
                   for (int j = 0; j < gs.length; j++) {
                        GraphicsDevice gd = gs[j];
                        GraphicsConfiguration[] gc = gd.getConfigurations();
                        for (int i=0; i < gc.length; i++) {
                             screenS = screenS.union(gc.getBounds());
                   screenSize = screenS.getSize ();
              } catch (HeadlessException e) {
                   screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
              if (x > screenSize.width) {
                   x = screenSize.width-getSize().width;
              if (y > screenSize.height) {
                   y = screenSize.height-getSize().height;
              super.setLocation (x, y);
    but it doesn't help. By the way: I can't (!) check in this function for negative x-values because computer 1 allows negative x-values, computer 2 NOT.
    I need something to get out if a x,y-location is situated in a viewable screencontent AND this should work on every computer.....
    any help would be great
    Thanks a lot

    Has anyone solved this problem yet? I've tried several variants in the call to Frame's getMaximizeBounds() and cannot reliably get it to work. For one particular monitor setup (1280x1024, 1024x1280, and 1024x1280), I can find the magic numbers to make it maximize across both 1024x1280 monitors.
    For my scenario, the left monitor is 1280x1224 and is primary, the other two are used to run the Java application. When maximized, it should take over the complete 2048x1280 space of both portrait monitors (middle and right monitors). When not maximized (in NORMAL mode), it the window takes over the space of the middle 1024x1280 monitor.
    To make it work, I use the following call:
    // x = 0, y = 1, width = 2304, and height = 1280
    m_windowFrame.setMaximizedBounds(new Rectangle(0,1,2304, 1280));
    - if "y" is 0, which I would expect should be ok, the maximize defaults to having as if I pass in null (it maximized to only one monitor).
    - if "width" is the correct amount (2048), it doesn't use all the space of both portrait monitors. For some reason, if I use with width of the primary and the width of one portrait, it works.
    This doesn't make a bit of sense why these number works. If someone can shed light on how this call works, I would very much appreciate it.
    Thank you

  • Why do we need JRootPane ?

    Hello!
    My feeling about JRootPane is that it would have simpler to have
    JFrame, JDialog, JWindow, and JApplet (indirect) subclasses of
    JComponent. And so the class JRootPane would be useless.
    But it is not. anyone knows why?
    I guess that my question can be put in other words: Why JFrame, JDialog, ... do not inherit from JComponent?
    cheers,
    Alexandre

    You will find a very helpful description of the Swing Frame architecture in Using Top-Level Containers and a thorough discussion of Root Panes in How to Use Root Panes in the Tutorial.

  • Freezed modal jdialog in japplet

    I have made an applet program whose method javascript calls. And the method of the applet shows modal JDialog. But, after showing modal JDialog, the applet is locked.
    In Windows XP + JRE 6.2 + Firefox 2.0, it is locked just after showing modal JDialog.
    But in Windowx XP + JRE 5,4,3 + Firefox 2.0/IE, it is OK(working well) And, in Other OSes and Other browser, it is OK
    You can test this and watch java source in the below link.
    http://whoispso.cafe24.com/freezed_dialog_in_ff/FreezedJDialogInFFInJRE6InWindows.html
    http://whoispso.cafe24.com/freezed_dialog_in_ff/FreezedJDialogInFFInJRE6InWindows.java
    import java.awt.Frame;
    import javax.swing.JApplet;
    import javax.swing.JDialog;
    import javax.swing.JOptionPane;
    public class FreezedJDialogInFFInJRE6InWindows extends JApplet {
         private Frame rootFrame;
         public void init() {
              rootFrame = JOptionPane.getFrameForComponent(this);
              showJDialog("it is called from init()");          
         public String showJDialogFromJS() {
              String msg = "it is called from showJDialogFromJS()";
              showJDialog(msg);
              return msg;          
         private void showJDialog(String msg) {
              JDialog dialog = new JDialog(rootFrame, msg, true);
              dialog.setSize(300, 300);
              dialog.setResizable(false);
              dialog.setVisible(true);
    {code}
    {code:javascript}
    <HTML>
    <HEAD>
         <SCRIPT language = "javascript">
              function install() {
                   var applet_tag = '<APPLET ID = "dialog_test"' +
                                       'CODE = "FreezedJDialogInIEInJRE5InWindows.class"' +
                                       'WIDTH = "0"' +
                                       'HEIGHT = "0">';
                   document.getElementById("applet_space").innerHTML = applet_tag;
              function showJDialog() {
                   if(!is_installed()) {
                        alert("not installed!");
                        return;
                   var returnValue;
                   try {
                        returnValue = document.dialog_test.showJDialogFromJS();
                   } catch (err) {
                        alert(err);
                   alert("return value is " + returnValue);
              function is_installed() {
                   if(document.dialog_test == null) {
                        return false;
                   } else {
                        return true;
         </SCRIPT>
    </HEAD>
    <BODY>
    <DIV id = "applet_space"></DIV>
    <SCRIPT>
         install();
    </SCRIPT>
    <INPUT TYPE="button" NAME="button" VALUE="showJDialog()" onClick=javascript:showJDialog()>
    </BODY>
    </HTML>
    {code}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    Try placing it on the awt thread, for example:
    private void showJDialog(String msg) {
                java.awt.EventQueue.invokeLater(new Runnable() {
                    public void run() {
                          JDialog dialog = new JDialog(rootFrame, msg, true);
                          dialog.setSize(300, 300);
                          dialog.setResizable(false);
                          dialog.setVisible(true);
    {code}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Jdialog Help needed in JApplet

    i have program and opens a dialog after click on a button. but dialog hides if applet is clicked. i need applet clickable but dialog should be on top of applet. I checked How To make Dialog in http://java.sun.com/j2se/1.5.0/docs/api/ and found the sample is very good but is complecated for me understand Framing explanation given.
    Can some one please change/guide me on this program ?
    thanks
    import javax.swing.*;
    public class NewJApplet extends javax.swing.JApplet {
        JFrame frame ;
        /** Initializes the applet NewJApplet */   
        public void init() {
            try {
                java.awt.EventQueue.invokeAndWait(new Runnable() {
                    public void run() {
                        initComponents();
            }catch(Exception e){}                             
        // <editor-fold defaultstate="collapsed" desc=" Generated Code ">
        private void initComponents() {
            jButton1 = new javax.swing.JButton();
            jButton1.setText("jButton1");
            jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
                public void mouseClicked(java.awt.event.MouseEvent evt) {
                    jButton1MouseClicked(evt);
            getContentPane().add(jButton1, java.awt.BorderLayout.CENTER);
        }// </editor-fold>
    private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {                                     
        JDialog jd = new JDialog();
        jd.setVisible(true);       
        // Variables declaration - do not modify
        private javax.swing.JButton jButton1;
        // End of variables declaration
    }

    Try using this method:
    public void mensaje(String estado){
              JOptionPane.showMessageDialog(this,estado);
             }

  • JApplet cannot display JTooltip at right location !!!!!!!!

    I am using ATI 9200 graphic card with Hydravision, and connect two Dell 19 inchs LCD monitors to it. The applet was displayed on the secondary monitor. But the problem is that all the tooltips for textfields in the applet were displayed on the primary monitor.
    there is more problem with Hydravision. All of dialog boxes are displayed on the primary monitor while the applet is on the secondary monitor.
    I have set Hydravision's dialog control setting to "show on app's monitor", however it is still not working correctly.
    I just don't know if anybody else has this kind of problem when you are working
    with two monitors system.
    Thank you

    Hello Daniel,
    I do know that the Full Screen option is a QuickTime Pro-only feature if you play it in QuickTime. However, you should be able to play it in Full Screen under iTunes without the Pro version of QuickTime by going in the iTunes Preferences --> Playback --> Play videos: full screen.
    As with the other sizes, I'm not quite sure the reason they're greyed out; You can do Half and Double with regular QuickTime.

  • Is correct? Application (JFrame) to Applet (JApplet)

    I need to convert a java application (JFrame) into an applet (JApplet), and I have seen a few "big steps":
    1�: make the class extends to JApplet instead of a JFrame
    2�: To replace the construction method by init ()
    3�: To comment the main method
    Is correct?, because I have some doubts that later I�ll explain
    Thanks

    I think in the init method (in a JApplet) I cannot call the super method. but my problem is how to change this? if in others files (in Files.java) I have calls to super metod, because thus it constructs a dialog box, asking for a file.
    In file Files.java I have a class called "Abort" (extends to JDialog) in whitch:
    /* class Files.java */
    class Abort extends JDialog
              boolean abort = true;
              JTextArea mensage = null;
              JButton acept = new JButton("Acept");
              JButton cancel = new JButton("Cancel");
              Abort(String nanemFile)
                   super(MainClassFile.mainWindow, " Attention!", true);
    /* clas Files.java */Please help

  • How can I change the layout on this JDialog?

    Hi , I have the following Dialog with some content. As of now, the line after the separator is displayed in two lines. I was looking for a way to show that in one line and change the column widths a bit so that the rest of the content can each be shown on one line as well, according to the look and feel of a table.
    Here's the code:Please download [TableLayout.jar|http://java.sun.com/products/jfc/tsc/articles/tablelayout/apps/TableLayout.jar] in order to compile.
    Thanks!
    import layout.TableLayout;
    import java.awt.BorderLayout;
    import java.awt.Component;
    import javax.swing.JButton;
    import javax.swing.JDialog;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JSeparator;
    import javax.swing.JTabbedPane;
    import javax.swing.JTextPane;
    import javax.swing.text.StyledEditorKit;
    public class MyDialogTest implements layout.TableLayoutConstants {
         JTabbedPane pane;
         JDialog myDialog;
         JTextPane infoPanel;
        public MyDialogTest() {
             myDialog = new JDialog();
             myDialog.setTitle("MyDialogTest");
             pane = new JTabbedPane();
             JPanel panel = new JPanel(new BorderLayout());
             panel.add(makeTab(), BorderLayout.CENTER);
             pane.addTab("About", panel);
             myDialog.getContentPane().add(pane);
             myDialog.setSize(500, 620);
             myDialog.setResizable(false);
             myDialog.setVisible(true);
        private Component makeTab() {
             JPanel aboutPanel = new JPanel();
            double [][] size = {{PREFERRED, FILL},{PREFERRED, PREFERRED, PREFERRED, PREFERRED, PREFERRED, PREFERRED, PREFERRED, PREFERRED, PREFERRED, PREFERRED, FILL}};
            TableLayout layout = new TableLayout(size);
            aboutPanel.setLayout(layout);
            JLabel headerLabel = new JLabel("About This Application");
            aboutPanel.add(headerLabel, "0, 0, 1, 0");
            aboutPanel.add(new JLabel("Version 4.1"), "0, 1, 1, 1");
            aboutPanel.add(new JLabel(" "), "0, 2, 1, 2");
            aboutPanel.add(new JLabel("Customer Service: 1-800-888-8888"), "0, 3, 1, 3");
            JLabel yahooUrl = new JLabel("www.yahoo.com");
            aboutPanel.add(yahooUrl, "0, 4");
            aboutPanel.add(new JLabel(" "), "0, 5");
            aboutPanel.add(new JSeparator(), "0, 6, 1, 6");
            aboutPanel.add(new JLabel(" "), "0, 7");
            infoPanel = new JTextPane();
            infoPanel.setEditable(false);
            infoPanel.setEditorKit(new StyledEditorKit());
            infoPanel.setContentType("text/html");
            makeInfoPanel();
            aboutPanel.add(infoPanel, "0, 8, 1, 8");
            JButton copyToClipboardButton = new JButton("Button1");
            JButton moreInformationButton = new JButton("Button2");
            JPanel buttonPanel = new JPanel();
            buttonPanel.add(copyToClipboardButton);
            buttonPanel.add(moreInformationButton);
            aboutPanel.add(buttonPanel, "0, 9");
            return aboutPanel;
        private void makeInfoPanel() {
              StringBuffer infoPaneContent = new StringBuffer("<html><head></head><body><table>");
              infoPaneContent.append("<tr><td>Version 4.1 (build  111708-063624"+ "</td></tr>");
              infoPaneContent.append("<tr><td>Customer IP Address:</td>&nbsp <td>10.53.62.11</td></tr>");
              infoPaneContent.append("<tr><td>JMS Server:</td>&nbsp <td>myserver</td></tr>");
              infoPaneContent.append("<tr><td>Quote Server:</td>&nbsp <td>qs2w62m3/qs106w60m3</td></tr>");
              infoPaneContent.append("<tr><td>Login ID:</td>&nbsp <td>programmer girl</td></tr>");
              infoPaneContent.append("<tr><td>Java Version:</td> &nbsp<td>"+ System.getProperty("java.version") + "</td></tr>");
              infoPaneContent.append("<tr><td>Operating System:</td> &nbsp<td>"+ System.getProperty("os.name") + " "+ System.getProperty("os.version") + " ("+ ")" + "</td></tr>");
             infoPaneContent.append("<tr><td>Browser Version:</td>&nbsp <td>"+ "Mozilla/4.0(compatible: MSIE 6.0; Windows NT 5.1; SV!; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; .NET CLR 3.0.04506.648" + "</td></tr>");
              Runtime rt = Runtime.getRuntime();
              infoPaneContent.append("<tr><td>Free Memory (KB):</td>&nbsp <td>("+ rt.freeMemory() / 1000 + " / " + rt.totalMemory() / 1000+ ")</td></tr>");
              infoPaneContent.append("<tr><td>Symbols In Use:</td>&nbsp<td>symbol</td></tr>");
              infoPaneContent.append("<tr><td>JMS :</td>&nbsp<td>connected</td></tr>");
              infoPaneContent.append("<tr><td>Market Data :</td>&nbsp<td>connected</td></tr>");
              infoPaneContent.append("<tr></tr>");
              infoPaneContent.append("<tr></tr>");
              infoPaneContent.append("</table></body></html>");
              infoPanel.setText(infoPaneContent.toString());
         public static void main(String[] args) {
              MyDialogTest test = new MyDialogTest();
    }

    Just sign out and sign in with your UK Apple ID
    Edit: If you press your name on this page (top left), you get "Actions" on the right side. Here you can change timezone, location etc.

  • Problems with 'background' JFrame focus when adding a modal JDialog

    Hi all,
    I'm trying to add a modal JDialog to my JFrame (to be used for data entry), although I'm having issues with the JFrame 'focus'. Basically, at the moment my program launches the JFrame and JDialog (on program load) fine. But then - if I switch to another program (say, my browser) and then I try switching back to my program, it only shows the JDialog and the main JFrame is nowhere to be seen.
    In many ways the functionality I'm looking for is that of Notepad: when you open the Find/Replace box (albeit it isn't modal), you can switch to another program, and then when you switch back to Notepad both the main frame and 'JDialog'-esque box is still showing.
    I've been trying to get this to work for a couple of hours but can't seem to. The closest I have got is to add a WindowFocusListener to my JDialog and I hide it via setVisible(false) once windowLostFocus() is fired (then my plan was to implement a similar functionality in my JFrame class - albeit with windowGainedFocus - to show the JDialog again, i.e. once the user switches back to the program). Unfortunately this doesn't seem to work; I can't seem to get any window or window focus listeners to actually fire any methods, in fact?
    I hope that kind of makes sense lol. In short I'm looking for Notepad CTRL+R esque functionality, albeit with a modal box. As for a 'short' code listing:
    Main.java
    // Not all of these required for the code excerpt of course.
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Component;
    import java.awt.Dimension;
    import java.awt.GraphicsEnvironment;
    import java.awt.Rectangle;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.ComponentAdapter;
    import java.awt.event.ComponentEvent;
    import java.awt.event.FocusEvent;
    import java.awt.event.FocusListener;
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
    import java.awt.event.WindowFocusListener;
    import java.awt.event.WindowListener;
    import java.beans.PropertyChangeEvent;
    import java.beans.PropertyChangeListener;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JSplitPane;
    import javax.swing.UIManager;
    import javax.swing.plaf.basic.BasicSplitPaneDivider;
    import javax.swing.plaf.basic.BasicSplitPaneUI;
    public class Main extends JFrame implements ActionListener, WindowFocusListener, WindowListener, FocusListener {
         static JFrame frame;
         private static int programWidth;
         private static int programHeight;
         private static int minimumProgramWidth = 700;
         private static int minimumProgramHeight = 550;
         public static SetupProject setupProjectDialog;
         public Main() {
              // Setup the overall GUI of the program
         private static void createSetupProjectDialog() {
              // Now open the 'Setup Your Project' dialog box
              // !!! Naturally this wouldn't auto-open on load if the user has already created a project
              setupProjectDialog = new SetupProject( frame, "Create Your Website Project", true );
              // Okay, for this we want it to be (say) 70% of the progamWidth/height, OR *slightly* (-25px) smaller than the minimum size of 700/550
              // Change (base on programWidth/Height) then setLocation
              int currProgramWidth = getProgramWidth();
              int currProgramHeight = getProgramHeight();
              int possibleWidth = (int) (currProgramWidth * 0.7);
              int possibleHeight = (int) (currProgramHeight * 0.7);
              // Set the size and location of the JDialog as needed
              if( (possibleWidth > (minimumProgramWidth-25)) && (possibleHeight > (minimumProgramHeight-25)) ) {
                   setupProjectDialog.setPreferredSize( new Dimension(possibleWidth,possibleHeight) );
                   setupProjectDialog.setLocation( ((currProgramWidth/2)-(possibleWidth/2)), ((currProgramHeight/2)-(possibleHeight/2)) );
               else {
                   setupProjectDialog.setPreferredSize( new Dimension( (minimumProgramWidth-25), (minimumProgramHeight-25)) );
                   setupProjectDialog.setLocation( ((currProgramWidth/2)-((minimumProgramWidth-25)/2)), ((currProgramHeight/2)-((minimumProgramHeight-25)/2)) );
              setupProjectDialog.setResizable(false);
              setupProjectDialog.toFront();
              setupProjectDialog.pack();
              setupProjectDialog.setVisible(true);
         public static void main ( String[] args ) {
              Main frame = new Main();
              frame.pack();
              frame.setVisible(true);
              createSetupProjectDialog();
            // None of these get fired when the Jframe is switched to. I also tried a ComponentListener, but had no joy there either.
         public void windowGainedFocus(WindowEvent e) {
              System.out.println("Gained");
              setupProjectDialog.setVisible(true);
         public void windowLostFocus(WindowEvent e) {
              System.out.println("GainedLost");
         public void windowOpened(WindowEvent e) {
              System.out.println("YAY1!");
         public void windowClosing(WindowEvent e) {
              System.out.println("YAY2!");
         public void windowClosed(WindowEvent e) {
              System.out.println("YAY3!");
         public void windowIconified(WindowEvent e) {
              System.out.println("YAY4!");
         public void windowDeiconified(WindowEvent e) {
              System.out.println("YAY5!");
         public void windowActivated(WindowEvent e) {
              System.out.println("YAY6!");
         public void windowDeactivated(WindowEvent e) {
              System.out.println("YAY7!");
         public void focusGained(FocusEvent e) {
              System.out.println("YAY8!");
         public void focusLost(FocusEvent e) {
              System.out.println("YAY9!");
    SetupProject.java
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.WindowEvent;
    import java.awt.event.WindowFocusListener;
    import java.awt.event.WindowListener;
    import java.io.IOException;
    import java.net.URL;
    import javax.imageio.ImageIO;
    import javax.swing.JDialog;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    public class SetupProject extends JDialog implements ActionListener {
         public SetupProject( final JFrame frame, String title, boolean modal ) {
              // Setup the JDialog
              super( frame, title, modal );
              setDefaultCloseOperation( JDialog.DISPOSE_ON_CLOSE );
              // Bad code. Is only temporary
              add( new JLabel("This is a test.") );
              // !!! TESTING
              addWindowFocusListener( new WindowFocusListener() {
                   public void windowGainedFocus(WindowEvent e) {
                        // Naturally this now doesn't get called after the setVisible(false) call below
                   public void windowLostFocus(WindowEvent e) {
                        System.out.println("Lost");
                        setVisible(false); // Doing this sort of thing since frame.someMethod() always fires a null pointer exception?!
    }Any help would be very much greatly appreciated.
    Thanks!
    Tristan

    Hi,
    Many thanks for the reply. Isn't that what I'm doing with the super() call though?
    As in, in Main.java I'm doing:
    setupProjectDialog = new SetupProject( frame, "Create Your Website Project", true );Then the constructor in SetupProject is:
    public SetupProject( final JFrame frame, String title, boolean modal ) {
              // Setup the JDialog
              super( frame, title, modal );
              And isn't the super call (since the class extends JDialog) essentially like doing new JDialog(frame,title,modal)?
    If not, that would make sense due to the null pointer exception errors I've been getting. Although I did think I'd done it right hence am confused as to the right way to handle this,if so.
    Thanks,
    Tristan
    Edited by: 802573 on 20-Oct-2010 08:27

Maybe you are looking for

  • Apple Remote Control and Plex

    Yesterday, I installed Plex to see if I would enjoy it as much as Front Row, which I use constantly. I haven't upgraded to Lion because I don't want to lose Front Row. Now, as a result, my Apple Remote control no longer works. I uninstalled Plex, but

  • HP Instant Ink for HP Officejet Pro 8600 e-All-in-One

    I just purchased a new HP Officejet Pro 8600 e-All-in-One printer and was setting up HP Connected, etc. I came across HP's new service for ink called HP Instant Ink and was immediately sold. I went to go and sign up and the prompt told me that my pri

  • RPM Measurement using Quadrature Encoder and PXI 6602 counter

    Hi, I am on a project at work where I need to verify the speed (in RPM) of an unloaded motor which can operate up to 1400 rpm.  After doing some research, i determined that a quadrature encoder could be used to make the measurement.  I am looking at

  • Create user with dba privileges

    How do I create a user with DBA privileges in Oracle? The user should be able to create, insert, delete, truncate and other functions without any limits. Do I have to issue GRANT statements?

  • Photos lost after Yosemite update/no backup

    I looked in my Masters folder too. Nothing. I have two Mac laptops and had enabled sharing. I'm so sick about this!