1 2 Previous Next 23 Replies Latest reply on May 20, 2003 10:16 AM by 807546 Go to original post
      • 15. Re: Icon in JDialog
        807546
        You are correct that when you pass the parent frame object to the JDialog's constructor it geys the icon of the parent Frame.There is no other way to set the icon.May be your syntax is not correct.
        For eg.


        public class TestDialog extends javax.swing.JDialog{

        public TestDialog (){
        super((java.awt.Frame)com.sun.MyFrame);
        //MyFrame is your parent frame in package com.sun with a specific icon
        }
        }

        This is the correct procedure.
        Thanks
        Pallav
        • 16. Re: Icon in JDialog
          807546
          To be able to set the icon of a JDialog you will have to introduce a dummy JFrame and use it as parent,
          JFrame dummy = new JFrame();
          Toolkit kit = Toolkit.getDefaultToolkit();
          Image icon = kit.getImage("status16.gif");
          dummy.setIconImage(icon);
          Dialog status = new JDialog(dummy,"Status",true);
          This is okay for modal JDialogs. For non-modal (the user mustn't close it before doing something else) JDialogs there's a problem. In this case you will want the main JFrame to be the parent, otherwise you don't get the expected behaviour (the JDialogs "floats" on top of the application windows at all times). Facing this complication I chose to not use icons at all in my JDialogs. You do this by setting resizable to false,
          status.setResizable(false); // no icon
          • 17. Re: Icon in JDialog
            807546
            Hi. I solve this problem resetting the icon internally the dialog's creator:

            ------------------
            /** Creates new form LoginDialog */
            public LoginDialog(Frame parent, boolean modal, ImageIcon icona) {

            this(parent, modal);
            this.setTitle("Dialog Title");
            parent.setIconImage(icona.getImage());
            ...
            ------------------

            I don't think this is very elegant, but it works in modal and not modal mode.
            I hope to have given help. Bye.
            • 18. Re: Icon in JDialog
              807546
              Hi. I solve this problem resetting the icon internally
              the dialog's creator:

              ------------------
              /** Creates new form LoginDialog */
              public LoginDialog(Frame parent, boolean modal,
              ImageIcon icona) {

              this(parent, modal);
              this.setTitle("Dialog Title");
              parent.setIconImage(icona.getImage());
              ...
              ------------------

              I don't think this is very elegant, but it works in
              modal and not modal mode.
              I hope to have given help. Bye.
              You seem to change the icon of the parent. This means the main application window will have a different icon while the dialog is displayed, doesn't it?

              I can accept Sun's explanation but I still believe a programmer should be able to set any icon at will (se my post above uj).
              • 19. Re: Icon in JDialog
                807546
                And why didn't uj get the duke for providing that answer. Now when she's dead it's to late.
                • 20. Re: Icon in JDialog
                  807546
                  And why didn't uj get the duke for providing that
                  answer.
                  Because it was a bit late?
                  • 21. Re: Icon in JDialog
                    807546
                    And why didn't uj get the duke for providing that
                    answer.
                    Because it was a bit late?
                    Well, here I am, the late uj -:)
                    • 22. Re: Icon in JDialog
                      807546
                      you can give icon to the JDialog by giving icon to the frame, in which you are calling that dialog. By giving icon to the frame this will use that icon to the dialog box also

                      for frame

                      frame.setIconImage(Toolkit.createImage("icon.gif"));
                      • 23. Re: Icon in JDialog
                        807546
                        you can give icon to the JDialog by giving icon to the
                        frame, in which you are calling that dialog. By
                        giving icon to the frame this will use that icon to
                        the dialog box also

                        for frame

                        frame.setIconImage(Toolkit.createImage("icon.gif"));
                        Yes but the problem is you want to use an icon in your dialog that is DIFFERENT from the one you have in the main application window.

                        As I see it this is only possible if you create a DUMMY parent JFrame. But by doing this you will LOSE important properties of a non-modal dialog window. It will no longer automatically "float" above your main application window as you will want it to do.

                        I really tried everything but ended up not using icons at all in my non-modal dialogs (se my post above (uj) for details).
                        1 2 Previous Next