Icon on JDialog

Hi ,
Can anyone let me know how to set the icon in the caption bar for JDialog. I am passing the Frame in the constructor but he is not showing the icon of the Frame. Dialog is set as Modal.
Constructor is like this:
public MyDialog(Frame frame,String title,boolean modal )
super(frame,title,modal);
Please help me..

Ah yes, forgot to mention that when you call setResizable(false) on a dialog, the icon disappears (does anyone know why?).
If you realy must have an icon and want to restrict the size of the dialog, one suggestion would be to add a component listener to the dialog which sets the dialog back to a fixed size in the componentResized(ComponentEvent e) method.
cheers,
Greg

Similar Messages

  • Setting icon in JDialog title bar.

    Hi all,
    Can u send me the code for setting the icon in the title bar of JDialog?
    Currently i'm working on linux.
    Is there any possible way to set it.

    1) Swing related questions should be posted in the Swing forum.
    2) Quit multi posting, you where given the answer yesterday when you originally posted this question.

  • Setting icon in JDialog

    Hi all
    I have a problem setting an icon in a JDialog. Now I know that JDialog's icon image will be the same as the icon image of its parent frame. Hence, setting the icon image of the parent frame which launches the JDialog will set the icon for the JDialog. But the problem lies here. It does not work the way it should. The JDialog is not getting the icon from the parent frame. Can somebody help me out with this problem? Is there any other way to set the icon for the JDialog explicitly - say something like a setIcon().
    Help will be really appreciated.
    Thanks.

    Hi,
    there is no setIcon(). There are some problems when your JDialog is not resizable and modal. Try some combinations with resizable and modal to find out whether thats the reason.
    Phil

  • Changing the Title Icon of JDialog

    Hello All,
    Is there any way to change the coffer cup icon which appears in the top of a JDialog?
    In JFrame,we can use setIconImage().But that doesn't work here.
    Could anyone give me a solution for my problem.?
    Thanks in Advance,
    Regards,
    Vijayakannan

    http://forum.java.sun.com/thread.jsp?forum=31&thread=406035

  • Java Icon in JDialog

    Hi all,
    Can some one tell me, how to remove the Java Icon from the left upper corner in the instance class of JDialog?
    Thanks,
    Genrry.

    Did you search the forum for related discussions on this topic? Keywords from your subject title would be a good place to start.

  • Image icon in JDialog

    i have a login UI , when i clich on change password it opens
    a JDialog , i am passing 2 parameters with the call, the username and the
    login frame object , In the constructor of Jdialog class i am again taking
    2
    parameters , the username and the frame object , and calling super with
    frame object, but the IconImage of the parent frame is not displayed in
    JDialog ... can anybody explain..

    I don't think I understand the problem. Can you be a little more specific?
    You have a frame with an icon. And then when you clic on a button of this frame, you show a dialog. Is that true?
    If it is, then it has to work. I've done several times without any trouble.
    class YourFrame extends JFrame
       JButton yourButton = new JButton();
      //more code
      //inside the method that it's call with yourButton is clicked
      YourDialog yourDialog = new YourDialog(this);
    class YourDialog extends JDialog
      //code
      public YourDialog(Frame parent)
       super(parent, "Tittle", true); //for example
    }This structure have to work.

  • How to set icon in JDialog

    In JFrame there is method setIconImage(Image) for setting image icon on title bar , but in case of JDialog how to it?

    In case you have not mentioned the owner of JDialog, java sets a hidden frame as its owner.Thefore you can set the icon on a JDialog dialog by
    ((java.awt.Frame)dialog.getOwner()).setIconImage(Image);
    Regards
    Shashi

  • Frame icon for JDialog

    Hi all,
    I have a JDialog which is passed an instance of JFrame as parent component in its constructor.
    The problem is that if i set the dialog as non resizable, the icon that appears in title bar(top left corner) goes.
    It is visible only when the dialog is kept resizable.
    Further the dialog is a modal dialog.
    Please help,
    Regards,
    vikalp setya
    [email protected]

    To work around the bug, add this to your JDialog
          addComponentListener(new ComponentAdapter() {               // need this to prevent window resizing
             public void componentResized(ComponentEvent e) {          // can't use setResizable(false) because then the icon in the title bar is gone
                if (size==null) return;  // must be set elsewhere when JDialog is visible
                setSize(size);  // restore the original size of JDialog
          });;o)
    V.V.

  • How can i change the icon in JDialog

    Hi,
    I have created a regular JDialog with new JDialog("Title");
    My problem is, the JDialog has the standard Java Icon.
    Is there a way to change this icon to a custom icon.
    I know you can change the icon in a JFrame, but haven't found anything how to change it in a JDialog.
    Any idea?

    Yep,
    there is no way to do it apart from using a different constructor:
    .... = new JDialog(Frame owner,String title)
    If you have set the Icon in owner , your JDialog will have the same icon.
    Phil

  • Icon on JDialog with setResizable(false)

    Hi ,
    Can anybody know how to provide an Icon on the caption bar for the JDialog when we set the resizable feature to 'false' ?
    I observed, when we do setResizable(true), icon comes up but does not
    show when we do setResizable(false).
    Also when we use JOptionpane.showMessageDialog() which is not set as resiable does not show up icons as well. Can we do anything in this context as well ?
    Thanking you in advance.

    Leave resizing enabled an add a componentResizedHandler which pack()s the dialog.
    Altough this will allow the user to resize the dialog, the dialog will also revert to it's initial size.
    HTH,
    Klaus

  • Change Coffee cup icon on JDialog & JOptionPane

    I try to change the coffee cup icon on my JDialog and JOptionPane.
    My JDialog box does not load the Parent Icon (JFrame icon), and not even show a coffee cup icon.
    My JOptionPane would just show a coffee cup icon, eventhough its parent is the above JDialog with no icon.
    Is there anyone know how to fix this?
    I'd like show my icon on the JOptionPane instead of the coffee cup icon.
    And also to show my icon on the JDialog instead of nothing, not even a coffee icon.
    Any help is appreciated.
    CL

    Passing a parent with the desired icon to the JDialog/JOptionPane should solve your problem, however there is a bug in swing that prevents any icon from showing in the titlebar if a JDialog is made non-resizable (through a call to setResizable(false)).
    The bug adatabse says that this has been resolved but I am using jdk 1.3.1 and continue to have this problem.

  • Title icon in jdialog

    hi
    how can one set an icon in title bar of a jdialog similar to jframe

    You have to specify the parent in JDialog's constructor and the JDialog will display the same icon as the parent:JFrame yourJFrame = new JFrame();
    yourJFrame.setIconImage(yourIconImage);
    JDialog jd = new JDialog(yourJFrame, "My JDialog");

  • How to set the icon for the entire application with JFrame.setIconImage

    I set the icon on the main frame using JFrame.setIconImage(). The icon is shown properly in the main frame.
    If more JFrames are opened from the main frame, the newly opened JFrames also show the icon.
    However if JDialogs are opended, in some cases the icon set on the main frame is shown and in other cases the coffee cup.
    What is JFrame.setIconImage() expected to do? Setting the icon for a single JFrame or the entire application?
    How can I set the icon for the entire application?
    How can I set the icon for JDialogs?
    Thank you

    In order for your dialogs to use the same icon as the frame, you must parent the dialogs to the frame which has the custom icon.
    See the following thread for more information: http://forum.java.sun.com/thread.jsp?forum=57&thread=362542
    cheers,
    Greg

  • Add maximumsize icon to title bar in JDialog

    My question is how to add a maximumsize icon to the title bar of JDialog, i want to create a dialog that when user double-click the JDialog's title bar or click the maximumsize icon in the JDialog's title bar the dialog can be displayed as maximum size. it just likes Frame.
    Thanks in advance!
    lupeng
    [email protected]

    Hi Lupeng,
    I can think of 2 approaches, firstly and probably the most easiest is to use a frame to mimic the behaviour of the dialog.
    Secondly, implement your own L&F for dialogs by wrting your own RootPaneUI that uses your own version of TitlePane. The TitlePane class will take care of the buttons and mouse handling. Have a look at BasicRootPaneUI to get a better understanding of the implementation ;)
    N35Sy

  • Setting Icon Image in JDialog

    The following code sets the top-left icon of a JDialog box.But when I uncomment the line
    'setResizable(false)' the Icon is not seen.
    So how do run the code if I want the JDialog box not Resizable ?
    Code is as follows...................................
    import javax.swing.event.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.awt.*;
    public class Main extends JFrame {
    private AboutBox about;
    public Main() {
    super("Main test");
    setSize(450, 350);
    ImageIcon icon = new ImageIcon("no.gif");
    setIconImage(icon.getImage());
    JButton button = new JButton("Open dialog");
    getContentPane().setLayout(new FlowLayout());
    getContentPane().add(button);
    button.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent ae) {
    about = new AboutBox(new JFrame());
    about.setVisible(true);
    addWindowListener(new WindowAdapter() {
    public void windowClosing(WindowEvent we) {
    System.exit(0);
    public static void main(String []args) {
    Main main = new Main();
    main.setVisible(true);
    class AboutBox extends JDialog {
    public AboutBox(JFrame owner) {
    super(owner, "About Swing Menu", true);
    ImageIcon icon = new ImageIcon("no1.gif");
    owner.setIconImage(icon.getImage());
    JButton button = new JButton("Close");
    getContentPane().setLayout(new FlowLayout());
    getContentPane().add(button);
    button.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent ae) {
    dispose();
    setSize(250, 150);
    // setModal(true);
    // setResizable(false);

    add a component listerner and override the componentResized.
    jframe.addComponentListener(new ComponentAdapter() {
              public void componentResized(ComponentEvent e) {
                        //code to reset back to the original window size
    User can still do the "resizing", but once user releases the mouse, it will reset back to the original size

Maybe you are looking for