JDialog Dispose and WindowClosing

Hi all. I'm trying to get my JDialog to correctly close when it is disposed, but with no luck. Here's a sample code showing the problem. The application will not correctly end because the JDialog is still around.
public class TestJDialog {
     public TestJDialog() {
          super();
     public static void main(String[] args) {
          JDialog d = new JDialog((Frame) null, "Hello");
          d.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
          d.addWindowListener(new JDialogWindowAdapter(d));
          d.show();
          //This line will hang your system.
          //Should end the program but doesn't.  This only way
          //this program will end is if you remove the bottom
          //line and click on the x in the dialog.
          d.dispose();
class JDialogWindowAdapter extends WindowAdapter {
     private JDialog m_dialog = null;
      * Constructs the adapter.
      * @param d the dialog to listen to.
     public JDialogWindowAdapter(JDialog d) {
          m_dialog = d;
     public void windowClosing(WindowEvent e) {
          super.windowClosing(e);
          //Dispose the hidden parent so that there are
          //no more references to the dialog and it can
          //be correctly garbage collected.
           ((Window) m_dialog.getParent()).dispose();
}I've looked through the forums, but a lot of people say use EXIT_ON_CLOSE, but that's not possible with my program. I just need to find a way to correctly fire the window closing event using dispose.
Thanks!

I think I know why the first one fails but the second on works.
public static void main(String[] args) {          
JDialog d = new JDialog((Frame) null, "Hello");
d.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
d.addWindowListener(new JDialogWindowAdapter(d));
d.show();
System.out.println( d.getParent() instanceof JFrame);
System.out.println( d.getParent().getClass().getName());
((Window)d.getParent()).dispose();
d.dispose();
prints out:
false
javax.swing.SwingUtilities$1 <----------What is that?????!!!!?!!?!?!?!?!?
public static void main(String[] args) {           
   JFrame frame = new JFrame(); 
   try {   
      JDialog d = new JDialog(frame, "Hello");             
      d.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);             
      d.show();  
      System.out.println( d.getParent() instanceof JFrame);
      System.out.println( d.getParent().getClass().getName());
      //d.dispose(); 
   } finally {  
      frame.dispose(); 
prints out:
true
javax.swing.JFrame <---------Yeah! It's correct
So JFrames correctly terminate, but whatever the hell that class is doesn't. What is that?

Similar Messages

  • JDialog, dispose, and JVM exit

    Why is it that running this code: import javax.swing.JDialog;
    public class Temp {
         public static void main(String args[]) {
              JDialog dialog = new JDialog();
              dialog.setVisible(true);
              dialog.dispose();
              dialog = null;
    }does not cause the JVM to terminate, but running this code: import javax.swing.JDialog;
    public class Temp {
         public static void main(String args[]) {
              JDialog dialog = new JDialog();
    //          dialog.setVisible(true);
              dialog.dispose();
              dialog = null;
    }does? What I want to happen is to cleanly dispose of the JDialog without terminating the JVM --- thus, System.exit(0) is not a viable solution here (unlike the similar JFrame problem).

    Use the setDefaultCloseOpration() thus:
    <code>
    import javax.swing.JDialog;
    public class Temp {
         public static void main(String args[]) {
              JDialog dialog = new JDialog();
         dialog.setVisible(true);
              dialog.dispose();
    dialog.setDefaultCloseOperation(JDialog.EXIT_ON_CLOSE);
    </code>

  • Detecting a JDialog opening and closing

    Hey everyone,
    This is a simple question, or at least, it should be :). I need a Timer to start when a JDialog opens and stop when it closes so a cute icon animation shows.
    So far, I managed to detect when the window opens, but not when it closes. This code is at the JDialog constructor:
    addWindowListener(new WindowAdapter()
                @Override
                public void windowClosed(WindowEvent we)
                    System.out.println("\t\t\t\twindowClosed");
                    busyIconTimer.stop();
                @Override
                public void windowOpened(WindowEvent we)
                    System.out.println("\t\t\t\twindowOpened");
                    busyIconTimer.start();
            });When I call "setVisible(true)", the windowClosed event is raised.
    When I call "setVisible(false", no event is called whatsoever (tried all the events available).
    Instead, if I call "mydialog.dispose()", the windowClosed event is called correctly.
    But after this, if I call "setVisible(true)" again, the windowOpened isn't called.
    Can anyone help me? :)
    Thanks in advance.

    I find that setVisible(false) calls windowDeactivate:
    import java.awt.Dimension;
    import java.awt.FlowLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.WindowEvent;
    import java.awt.event.WindowListener;
    import javax.swing.JButton;
    import javax.swing.JDialog;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    public class DialogStateListener
      private static void createAndShowUI()
        final JFrame frame = new JFrame("DialogStateListener");
        final JDialog dialog = new JDialog(frame, "Dialog", true);   
        JButton showDialogBtn = new JButton("Show Dialog");
        showDialogBtn.addActionListener(new ActionListener()
          public void actionPerformed(ActionEvent e)
            dialog.setVisible(true);
        frame.getContentPane().add(showDialogBtn);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.pack();
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
        JButton setVisibleFalseBtn = new JButton("setVisible(false)");
        JButton disposeBtn = new JButton("dispose");
        setVisibleFalseBtn.addActionListener(new ActionListener()
          public void actionPerformed(ActionEvent e)
            dialog.setVisible(false);
        disposeBtn.addActionListener(new ActionListener()
          public void actionPerformed(ActionEvent e)
            dialog.dispose();
        dialog.setPreferredSize(new Dimension(200, 200));
        JPanel contentPane = (JPanel)dialog.getContentPane();
        contentPane.setLayout(new FlowLayout());
        contentPane.add(setVisibleFalseBtn);
        contentPane.add(disposeBtn);
        dialog.pack();
        dialog.setLocationRelativeTo(null);
        dialog.addWindowListener(new WindowListener()
          public void windowActivated(WindowEvent e)
            System.out.println("window activated");
          @Override
          public void windowClosed(WindowEvent e)
            System.out.println("window closed");
          @Override
          public void windowClosing(WindowEvent e)
            System.out.println("window closing");
          @Override
          public void windowDeactivated(WindowEvent e)
            System.out.println("window deactivated");
          @Override
          public void windowDeiconified(WindowEvent e)
            System.out.println("window deiconified");
          @Override
          public void windowIconified(WindowEvent e)
            System.out.println("window iconified");
          @Override
          public void windowOpened(WindowEvent e)
            System.out.println("window opened");
      public static void main(String[] args)
        java.awt.EventQueue.invokeLater(new Runnable()
          public void run()
            createAndShowUI();
    }

  • JDialog size and components visibility

    hi
    I have a JDialog in which i have a panel and in the panel i have the components arranged as
    Label1 Label2
    Label3 TextBox1
    Label4 TextBox2
    Button1 Button2
    I have used GridBagLayout for the panel as well as for the Dialog.The following is the code i have used to create the JDialog,panel and its components
    JDialog inputdialog=new JDialog(this,true);
    inputdialog.setTitle("Modify");
    GridBagLayout layout=new GridBagLayout();
    JPanel panel=new JPanel();
    panel.setLayout(layout);
    GridBagConstraints gbc = new GridBagConstraints();
    JLabel key=new JLabel("Key");
    gbc.gridx=0;
    gbc.gridy=0;
    gbc.gridwidth=1;
    gbc.gridheight=1;
    gbc.anchor=gbc.CENTER;
    layout.setConstraints(key,gbc);
    panel.add(key);
    JLabel keylabel=new JLabel();
    keylabel.setText("SIMPLE");
    gbc.gridx=1;
    gbc.gridy=0;
    gbc.gridwidth=1;
    gbc.gridheight=1;
    gbc.anchor=gbc.NORTHWEST;
    // gbc.insets=new Insets(0,0,0,200);
    layout.setConstraints(keylabel,gbc);
    panel.add(keylabel);
    JLabel value=new JLabel("Value");
    gbc.gridx=0;
    gbc.gridy=1;
    gbc.gridwidth=1;
    gbc.gridheight=1;
    gbc.anchor=gbc.CENTER;
    layout.setConstraints(value,gbc);
    panel.add(value);
    JTextField valueTextField=new JTextField();
    gbc.gridx=1;
    gbc.gridy=1;
    gbc.gridwidth=1;
    gbc.gridheight=1;
    gbc.anchor=gbc.NORTHWEST;
    gbc.ipadx=100;
    layout.setConstraints(valueTextField,gbc);
    panel.add(valueTextField);
    JLabel comment=new JLabel("Comment");
    gbc.gridx=0;
    gbc.gridy=2;
    gbc.gridwidth=1;
    gbc.gridheight=1;
    gbc.anchor=gbc.CENTER;
    gbc.insets=new Insets(0,125,0,3);
    layout.setConstraints(comment,gbc);
    panel.add(comment);
    JTextField commentTextField=new JTextField();
    gbc.gridx=1;
    gbc.gridy=2;
    gbc.gridwidth=3;
    gbc.gridheight=1;
    gbc.ipadx=300;
    gbc.insets=new Insets(0,0,0,70);
    gbc.anchor=gbc.NORTHWEST;
    layout.setConstraints(commentTextField,gbc);
    panel.add(commentTextField);
    JButton ok=new JButton("OK");
    gbc.gridx=1;
    gbc.gridy=3;
    gbc.gridwidth=1;
    gbc.gridheight=1;
    gbc.ipadx=30;
    gbc.ipady=10;
    layout.setConstraints(ok,gbc);
    panel.add(ok);
    JButton cancel=new JButton("Cancel");
    gbc.gridx=2;
    gbc.gridy=3;
    gbc.gridwidth=1;
    gbc.gridheight=1;
    gbc.ipadx=30;
    gbc.ipady=10;
    gbc.insets=new Insets(0,0, 0,150 );
    layout.setConstraints(cancel, gbc);
    panel.add(cancel);
    inputdialog.setLayout(layout);
    gbc.gridx=0;
    gbc.gridy=0;
    gbc.ipadx=0;
    gbc.ipady=0;
    gbc.anchor=gbc.FIRST_LINE_START;
    gbc.insets=new Insets(80,0,900,1000);
    layout.setConstraints(panel,gbc);
    inputdialog.getContentPane().add(panel);
    inputdialog.setSize(400,200);
    inputdialog.setVisible(true);
    My question is i have set the Dialog size using setSize(400,200) but when the dialog is opened the components are not visible for that size of the dialog,the components appear only when the Dialog is maximized,i do not want that to happen i want the components to appear in the Dialog when the size of the Dialog is (400,200) and not when it is maximized.What should i do?
    thanks

    Hopefully this example would give you some ideas:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class DialogTest extends JFrame implements ActionListener {
         public DialogTest() {
              setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              JButton button = new JButton("Show Dialog");
              button.addActionListener(this);
              getContentPane().add(button);
              pack();
              setLocationRelativeTo(null);
              setVisible(true);
         public void actionPerformed(ActionEvent e) {
              JDialog dialog = new JDialog(this, true);
              dialog.setTitle("Testing");
              JPanel panel = new JPanel(new GridBagLayout());
              GridBagConstraints c = new GridBagConstraints();
              JLabel label;
              JButton button;
              JTextField textField;
              label = new JLabel("Key");
              c.gridx = 0;
              c.gridy = 0;
              c.insets = new Insets(5, 10, 5, 10);
              c.anchor = GridBagConstraints.CENTER;
              c.fill = GridBagConstraints.HORIZONTAL;
              panel.add(label, c);
              label = new JLabel("SIMPLE");
              c.gridx = 1;
              c.gridy = 0;
              panel.add(label, c);
              label = new JLabel("Value");
              c.gridx = 0;
              c.gridy = 1;
              panel.add(label, c);
              label = new JLabel("Comments");
              c.gridx = 0;
              c.gridy = 2;
              panel.add(label, c);
              textField = new JTextField(10);
              c.gridx = 1;
              c.gridy = 1;
              c.gridwidth = 2;
              c.insets = new Insets(5, 10, 5, 120);
              panel.add(textField, c);
              textField = new JTextField(20);
              c.gridx = 1;
              c.gridy = 2;
              c.insets = new Insets(5, 10, 5, 10);
              panel.add(textField, c);
              button = new JButton("OK");
              c.gridx = 1;
              c.gridy = 3;
              c.ipadx = 50;
              c.gridwidth = 1;
              panel.add(button, c);
              button = new JButton("Cancel");
              c.gridx = 2;
              c.gridy = 3;
              c.insets = new Insets(5, 5, 5, 50);
              panel.add(button, c);
              dialog.getContentPane().add(panel);
              dialog.pack();
              dialog.setVisible(true);
         public static void main(String[] args) { new DialogTest(); }
    }

  • Difference between dispose and setVisible(false)?

    What is the difference between dispose() and setVisible(false)? The only difference I see is that setVisible(false) and bring a window back by using a true flag, while dispose() cannot. Other than that, they appear to do the same thing.
    If I want to get rid of a window (with no intention of bring it back), which should I use?
    Also, is there a memory advantage to using one or the other?
    Thanks for any responses.

    setVisible just makes it visible or not...the advantage would be that you would not have to constantly spend time creating a new object, downside is it sits in memory until you really need it again.
    dispose will actually tell the gc it's ok to clean up the object...and you would have to make a new one each time you wanted to use it...advantage, frees up ram, disadvantage, takes time to create objects over and over.

  • Info path form gives error on submitting "The StateManager is disposing and calling ReleaseLockedStates() (Count=0)"

    Hi,
       I have created a very simple form which has 2 data connections all together. One connection is for a drop down which gets populated from a list within that site itself and the other data connection is used when I am submitting that form. But
    it is giving this error when I am submitting the form
    Error:
    The StateManager is disposing and calling ReleaseLockedStates() (Count=0)
    So, I have created a data connection library and uploaded the 2 udcx file in it and approved them but still the error is there.
    Please assist me on this. It is very urgent.

    Resolved the issue by changing the button type to "Submit"

  • JDialog dispose() not firing windowClosing()/windowClosed() event

    I have a small dialog that has 'OK' and 'CANCEL' buttons. When the user clicks on the 'X' in the top right hand corner to close the window, the windowClosing() event is fired on all listeners. However, calling dipose() when i click on the 'OK' or 'Cancel' buttons does not fire the event. I am sure this should work without a problem but i just cannot see what is going wrong.
    Andrew

    I'd have to test this, but there's some sort of logic to think that calling hide or dispose would not generate events. What would be the point? You know it's going to be closed, so you should tell anyone who needs to know. You can get the list of listeners and fire your own event if you wanted.
    Window.dispose() does fire a window closed event, though.
    If you want to simulate closing... This is from code I had written... some of it you can replace as appropriate (isJFrame(), etc).
          * Closes the window based on the window's default close operation. 
          * The reason for this method is, instead of just making the window
          * invisible or disposing it, to rely on either the default close
          * operation (for JFrames or JDialogs) or rely on the window's other
          * listeners to do whatever the application should do on the "window
          * closing" event. 
         private void doClose() {
              int closeOp = getDefaultCloseOperation();
              // send the window listeners a "window closing" event... 
              WindowEvent we = new WindowEvent(getWindow(), WindowEvent.WINDOW_CLOSING, null, 0, 0);
              WindowListener[] wl = getWindow().getWindowListeners();
              for(int i = 0; i < wl.length; i++) {
                   // this handler doesn't need to know...
                   if(wl[i] == this) {
                        continue;
                   wl.windowClosing(we);
              // if still visible, make it not (maybe)...
              if(getWindow().isVisible()) {
                   switch(closeOp) {
                        case WindowConstants.HIDE_ON_CLOSE:
                             getWindow().setVisible(false);
                             break;
                        case JFrame.EXIT_ON_CLOSE:
                        case WindowConstants.DISPOSE_ON_CLOSE:
                             getWindow().setVisible(false);
                             getWindow().dispose();
                             break;
                        case WindowConstants.DO_NOTHING_ON_CLOSE:
                        default:
         * Gets the default close operation of the frame or dialog.
         * @return the default close operation
         public int getDefaultCloseOperation() {
              if(isJFrame()) {
                   return ((JFrame)getWindow()).getDefaultCloseOperation();
              if(isJDialog()) {
                   return ((JDialog)getWindow()).getDefaultCloseOperation();
              // "do nothing" is, for all intents and purposes, the way AWT
              // Frame and Dialog work.
              return WindowConstants.DO_NOTHING_ON_CLOSE;

  • Use of dispose() and finalize()

    Hello everyone (first post ever). I have a question about a program that I'm currently working on that doesn't seem to be releasing system resources. Here's a brief description of my program and my problem:
    Program Description: It's a widget that queries a news file every couple of minutes to check if the file was updated. If it was updated, then the taskbar icon flashes and signals the user to click on it to open a window showing them the news.
    Problem: The main use of this program will be just sitting in the taskbar waiting and checking to see if there are any updates. However, after a user opens the window, the memory usage obviously spikes to show the content of the window. After the window is closed, the memory stays allocated and never seems to go back down to it's memory usage when it was just sitting in the taskbar. I have the window set to dispose on close and have fiddled around with adding finalize() and dispose() statements in a couple of different places. I also don't call anything from this class in any of my other classes.
    Here is my Window.class, where I'm hoping the problem is. Thanks.
    package mainFiles;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.border.*;
    // The part of the program that displays the main window of the widget
    public class Window extends JFrame implements ActionListener, WindowListener {
         private static final long serialVersionUID = 1L;
         // Declare the global variables used in the method
         private JButton updateButton;
         // The default constructor of the window
         public Window() {
              // Create the container for holding the content of the widget
              JFrame mainWindow = new JFrame();
              mainWindow.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
              this.centerWindow(mainWindow, 475, 350);
              mainWindow.addWindowListener(this);
              // Customize the look of the JFrame a little bit
              mainWindow.setIconImage(new ImageIcon("system/images/tray_inactive.gif").getImage());
              mainWindow.setTitle("Widget Text");
              mainWindow.setResizable(false);
              // Create the home panel of the widget
              WindowBackground homePanel = new WindowBackground();
              mainWindow.setContentPane(homePanel);
              homePanel.setLayout(new BoxLayout(homePanel, BoxLayout.X_AXIS));
              // Create the left side of the window
              JPanel leftPanel = new JPanel();
              leftPanel.setOpaque(false);
              leftPanel.setPreferredSize(new Dimension(104,324));
              homePanel.add(leftPanel);
              // Add a spacer to the left panel from the top
              leftPanel.add(Box.createRigidArea(new Dimension(104,16)));
              // Add the update button to the left side of the widget
              updateButton = new JButton("Refresh");
              updateButton.addActionListener(this);
              leftPanel.add(updateButton);
              // Create the right side of the window
              JPanel rightPanel = new JPanel();
              rightPanel.setOpaque(false);
              rightPanel.setPreferredSize(new Dimension(365,324));
              homePanel.add(rightPanel);
              // Add a spacer to the right panel from the top
              rightPanel.add(Box.createRigidArea(new Dimension(365,16)));
              // Create the scrollpane which allows the news to be scrolled up and down
              JScrollPane contentScrollPane = new JScrollPane(Content.mainPanel, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
                        JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
              contentScrollPane.getViewport().setOpaque(false);
              contentScrollPane.setOpaque(false);
              contentScrollPane.setEnabled(true);
              // Set the size of the scrollpane, then add it to the right panel
              contentScrollPane.setPreferredSize(new Dimension(356,290));
              rightPanel.add(contentScrollPane);
              // Create an empty border around the scrollpane to remove the border
              Border empty = new EmptyBorder(0,0,0,0);
              contentScrollPane.setBorder(empty);
              contentScrollPane.setViewportBorder(empty);
              // Whenever the window is opened, update the tray icon to inactive
              Widget.updateIconToInactive();
              // Show the window to the user
              mainWindow.setVisible(true);
         // If the main window of the widget is closed, then give the user the ability to make a new one
         public void windowClosing(WindowEvent event) {
              // Set the window to no longer being active
              Widget.windowActive = false;
              // *** This doesn't seem to work
              this.removeAll();
              System.gc();
         // For centering the window on the user's desktop
         public void centerWindow(JFrame window, int width, int height) {
              // Set the size of the window to the size wanted
              window.setSize(width, height);
              // Get the two sizes and compute the average size between them
              Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
              Dimension windowSize = window.getSize();
              int x = (screenSize.width / 2) - (windowSize.width / 2);
              int y = (screenSize.height / 2) - (windowSize.height / 2);
              // Set the location to the center of the screen
              window.setLocation(x, y);
         // Whenever a new WindowBackground is created, paint the background image on it
         public class WindowBackground extends JPanel {
              private static final long serialVersionUID = 1L;
              // Paint the background on the panel
              public void paintComponent(Graphics g) {
                   ImageIcon background = new ImageIcon("system/images/bg_window.gif");
                   background.paintIcon(this, g, 0, 0);
         // For responding to actions performed in the interface
         public void actionPerformed(ActionEvent event) {
              // If the user pushes the manual update button, then check for new updates
              if (event.getSource() == updateButton)
                   Content.check();
         // Although these aren't used, they must be included in the class
         public void windowActivated(WindowEvent arg0) {}
         public void windowClosed(WindowEvent arg0) {}
         public void windowDeactivated(WindowEvent arg0) {}
         public void windowDeiconified(WindowEvent arg0) {}
         public void windowIconified(WindowEvent arg0) {}
         public void windowOpened(WindowEvent arg0) {}
    }

    I'll try to describe it in some more detail:
    When the program first starts up, memory usage is around 9K to 11K, since the only task it has is to check an external file every five minutes to see if it's been updated. If there is an update, then the icon blinks which alerts the user that there is an update available. When they click on the icon, a window pops up displaying the news. Memory usage at this points run up to about 25K. Now this is where the problem comes in. After the window is closed, it should be disposed. Now, from what I understand, that means that the Garbage Collector should destroy it at some point and release the memory that's being used. However, many hours after the window has been closed, the memory usage is still at 25K. I just don't understand why it isn't using 9K-11K at that point.
    The main reason I care so much about memory usage is because this is a program that is going to be running in the background while users play PC games. It's mainly to get in touch with each other and tell each other when an event is happening in a specific game.

  • Dispose() and setVisible(false)

    I'm developing a program containing a wizard and I think the memory is not correctly managed.
    Here is an example of the implementation of two dialogs :
    public class A extends JDialog {
    private B nextDialog= null;
    nextButton.addActionListener(new ActionListener() {
    setVisible(false);
    if (nextDialog== null) {
    nextDialog= new B();
    nextDialog.setVisible(true);
    public class B extends JDialog {
    private A previousDialog= null;
    previousButton.addActionListener(new ActionListener() {
    setVisible(false);
    if (previousDialog== null) {
    previousDialog= new A();
    previousDialog.setVisible(true);
    Whenever I click on the nextButton, a new instance of the nextDialog is created and the present dialog is hidden.
    Similarly, whenever I click on the previousButton of the second Dialog, a new instance of the first Dialog is created and the present dialog is hidden.
    Thus, if I click on the nextButton then previousButton, nextButton, previousButton, etc... a lot of instances will be created.
    Should I use dispose() instead of setVisible(false) ?
    In this case each instance will be destroyed, won't it ?
    Should I use the singleton pattern ?
    In this case, the setVisible() method would be preferred to the destroy method ?
    Could you help me ?

    > int visIndex = getVisibleIndex(cont);
    String name = cont.getComponent(visIndex).getName();
    public static int getVisibleIndex(Container cont) {
    if(cont != null && cont.getLayout() instanceof
    CardLayout) {
    Component[] comps = cont.getComponents();
    for(int x = 0; x < comps.length; x++) {
    if(comps[x].isVisible()) {
    return x;
    return -1;
    Thanks for re-phrasing my point in a much more understandable way (it was late last night)

  • Question about JDialog - dispose()

    I use in my application a custom JDialog to get inputs from the user.
    When the "ok" button is pressed, i store all the inputs i need inside an object and then i dispose the JDialog.
    Now, the code which made the JDialog retrieve the object containing all the inputs through a call to a method of my custom JDialog.
    But this happens after i called dispose() on my JDialog.
    According to what i understood about it, it should release all the resources related to the JDialog and all its own children, so, how can i possibly access to it after i have disposed it?
    The object is not destroyed?
    Is there a time interval before it is "destroyed"?
    Thanks,
    Nite

    According to what i understood about it, it should release all the resources related to the JDialog and all its own children, so, how can i possibly access to it after i have disposed it?Read more carefully.
    Releases all of the native screen resources used by this Window, its subcomponents, and all of its owned children. That is, the resources for these Components will be destroyed, any memory they consume will be returned to the OS, and they will be marked as undisplayable.
    dispose() doesn't pre-empt the garbage collector. The native resources related to displaying the dialog are released, not the associated Java objects.
    Fresh resources will be obtained form the OS if the dialog is redisplayed.
    The Window and its subcomponents can be made displayable again by rebuilding the native resources with a subsequent call to pack or show.
    db

  • Calling a JDialog in the windowClosing Event of a JFrame

    hi
    As we had seen in many applications when u try to close the application a Dialog box will appear and it will ask whether we have to save it.I want to implement the same thing in my windowClosing Event of the Frame.I tried doing this by calling the Dialog i have created by using the show method in the window closing event of the Frame,but what happens is when i close the frame the Dialog box flickers and disappears.What should i do to avoid this flickering and Disppearing of the Dialog box.I want the Dialog box to stay on the screen.What should i do? any ideas?
    thanks

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class WindowClosingTest extends JFrame {
         public WindowClosingTest() {
              try {
                   setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
                   JButton button = new JButton("Close");
                   button.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent ae) { performClose(); }
                   addWindowListener(new WindowAdapter() {
                        public void windowClosing(WindowEvent we) { performClose(); }
                   getContentPane().add(button);
                   pack();
                   setLocationRelativeTo(null);
                   setVisible(true);
              } catch (Exception e) { e.printStackTrace(); }
         private void performClose() {
              int n = JOptionPane.showConfirmDialog(null, "Close?", "Confirm", JOptionPane.YES_NO_OPTION);
              if (n != 1) { System.exit(0); }
         public static void main(String[] args) { new WindowClosingTest(); }
    }

  • JDialog - Maximize and minimize button

    hey,
    Does anybody has an idea of how to add minimize and maximize buttons in a jdialog.
    thanks,
    pooja

    Use a JFrame.

  • JDialog dispose() problem

    I would like to close all the dialogs before opening a new one. I am using dispose() function for that, but the windows are not getting closed.
    Window[] wins = getOwner().getOwnedWindows();
    for (int k=0; k<wins.length; k++)
         wins[k].dispose();
    Any help is greatly appreciated.

    it is returning correct number of windows that are open. But when I am using dispose() on individual ones, they are not closing.

  • Modal JDialog needs disposing  TWICE!

    I have a simple JDialog that is modal over another JDialog. It has a cancel button whose action event simply calls dispose().
    However, on first invocation of cancel, the dispose() does not actually remove the dialog; it is only on a second click that dispose() actually does kill the dialog. I notice also that the first dispose() does not cause WindowClosed() to be called. I have verified that definitely only one instance of the dialog is being referenced (hashcode on each dispose is the same).
    The problem immediately goes away if I make the dialog non-modal, but I want it modal!!
    Any suggestions? Seems like a bug to me...(j2sdk1.4.1_01)

    By calling setVisible(false) the modal JDialog disappears and while it's invisible it's not modal (awt Dialogs do that, too). I was not able to reproduce your problem, but this piece of code may solve it:
    setVisible(false);
    dispose();

  • JOptionPane and JDialog.DO_NOTHING_ON_CLOSE broken?

    Hi there
    I've created a JDialog from a JOptionPane and I don't want the user to simply dispose of the dialog by clicking on the close button but they are still able and I'm sure that my code is correct. Is it my code that is wrong or is it a java bug? Oh I'm running on 1.3 BTW
    JFrame f = new JFrame();
    f.setSize(500, 500);
    f.setVisible(true);
    JOptionPane optionPane = new JOptionPane("Hello there", JOptionPane.INFORMATION_MESSAGE, JOptionPane.OK_CANCEL_OPTION);
    JDialog d = optionPane.createDialog(f, "Testing");
    d.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
    d.setVisible(true);I know that I can just set up a JDialog directly and use the setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE) and it seems to work properly but I would like to see it work for JOptionPane!
    Thanks in advance

    Sorry but this doesn't make it work either. I've looked at the code for createDialog in JOptionPane and it actually adds a WindowListener to the dialog in there as well as a propertyListener. On closing the option pane it calls a method in windowClosing of the windowListener which in turn fires a property change event which then tells the dialog to dispose itself so the addition of another windowAdapter to override the windowClosing method will not help :-(
    I've managed to get round it by doing something similar to
    JFrame frame = new JFrame();
    final JDialog dialog = new JDialog(frame, "Testing", true);
    JButton button = new JButton("OK");
    button.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        dialog.dispose();
    JOptionPane optionPane = new JOptionPane(button, JOptionPane.INFORMATION_MESSAGE, JOptionPane.OK_CANCEL_OPTION);
    dialog.setContentPane(optionPane);
    dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
    dialog.pack();
    dialog.setVisible(true);

Maybe you are looking for

  • I uploaded a song from GarageBand (originally on ipad) to the iCloud. It will show up on my iPhone, but now it won't show up on my iPad. HELP

    This has happened to many of my HIGHLY important songs. Because GarageBand loves to screw up songs, I decided to "Upload them to iCloud" Now, for a brief time, the song was still on the iPad. When I open the song up in my iPhone, the iPad version has

  • Problem with Sessions in JSP

    Hi, I am working on a JSP based website, where I am facing problem with sessions. The user is asked to login by providing her id and password. If found correct, a bean is created and populated with all her details and placed in session scope. I plan

  • Can I use Word 2010 with RoboHelp 8?

    Our company just upgraded to Word 2010 and, all of a sudden, when I try to generate printed documentation, RH gives me an error that I need Word 2000 or later. The OS is Windows XP Professional. Thanks!

  • Query related to User License.

    Hi all, I have some query related to User License. If we have 250 no of user license( with one developer), can we use them individually on DEV, QAS & PRD ? can we use them individually on differrent clients? what abt users on 000 client. Is they shou

  • Missing camera calibration profiles (Nikon P7700)

    Until recently I've been able to apply a choice of camera calibration profiles (e.g. Camera Landscape, Camera Portrait etc.) in the Develop Module to images taken with my Nikon Coolpix P7700. However, these have now vanished, and I'm only left with t