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)

Similar Messages

  • 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.

  • Flicker with heavyweight swing component and setVisible(false) on Linux

    Hi All,
    I'm using Java 6 update 14 on Ubuntu Jaunty.
    I'm developing a GUI for a system running linux. I'm using the Swing framework for the GUI but need to include 3D animation accelerated in hardware. I'm using the JOGL framework for applying the 3D animations which supplies one with two swing-like components, the GLJPanel and GLCanvas. These two components are lightweight and heavyweight swing components respectively.
    The difficulty arises when adding the heavyweight GLCanvas component into the gui. Often I need to do a setVisible(false) on the component in which case the GLCanvas hides correctly, but shows a flicker before the background is displayed. On digging a little deeper I found that because the GLCanvas is heavyweight, on linux it calls down to the sun.awt.X11 classes to do the setVisible(false) on hide. The very deepest call, the xSetVisible(false) method of the XBaseWindow class, causes the component to be replaced by first a grey backgound, and then the correct background. This intermediate grey background is causing the flicker.
    The source for the sun.awt.X11 packages was not available with the standard JDK 6 but I've found the open jdk source which matches the steps taken by the call. The xSetVisible method is as follows:
    0667:            public void xSetVisible(boolean visible) {
    0668:                if (log.isLoggable(Level.FINE))
    0669:                    log.fine("Setting visible on " + this  + " to " + visible);
    0670:                XToolkit.awtLock();
    0671:                try {
    0672:                    this .visible = visible;
    0673:                    if (visible) {
    0674:                        XlibWrapper.XMapWindow(XToolkit.getDisplay(),
    0675:                                getWindow());
    0676:                    } else {
    0677:                        XlibWrapper.XUnmapWindow(XToolkit.getDisplay(),
    0678:                                getWindow());
    0679:                    }
    0680:                    XlibWrapper.XFlush(XToolkit.getDisplay());
    0681:                } finally {
    0682:                    XToolkit.awtUnlock();
    0683:                }
    0684:            }I've found that the XlibWrapper.XFlush(XToolkit.getDisplay()) line (680) causes the grey to appear and then the XToolkit.awtUnlock(); line repaints the correct background.
    Using the lightwieght GLJPanel resolves this issue as it is a light weight component but unfortunately I'm unable to use it as the target system does not have the GLX 1.3 libraries required because of intel chipset driver issues (it has GLX 1.2). I cannot enable the opengl pipline either (-Dsun.java2d.opengl=True) for the same reason.
    Is there a way to configure a heavyweight component to avoid the operation in line 680? As far as I can tell, the flicker would disappear and the display would still be correctly rendered had this line not been executed. This problem is not present in windows.
    I've put together a minimal example of the problem. It requires the JOGL 1.1.1 libraries in the classpath. They can be found here: [JOGL-download|https://jogl.dev.java.net/servlets/ProjectDocumentList?folderID=11509&expandFolder=11509&folderID=11508]
    I've also found that running the program with the -Dsun.awt.noerasebackground=true vm argument reduces the flicker to just one incorrect frame.
    The program creates a swing app with a button to switch between the GLCanvas and a normal JPanel. When switching from the GLCanvas to the JPanel a grey flicker is noticeable on Linux. Step through the code in debug mode to the classes mentioned above to see the grey flicker frame manifest.
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Insets;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.media.opengl.GLCanvas;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JInternalFrame;
    import javax.swing.JPanel;
    import javax.swing.WindowConstants;
    import javax.swing.border.EmptyBorder;
    public class SwitchUsingJInternalFrameSwappedExample {
         private static JPanel glPanel;
         private static JPanel mainPanel;
         private static JPanel swingPanel1;
         private static boolean state;
         private static JInternalFrame layerFrame;
         private static GLCanvas glCanvas;
         public static void main(String[] args) {
              state = true;
              JFrame frame = new JFrame();
              frame.setSize(800, 800);
              frame.setContentPane(getMainPanel());
              frame.setVisible(true);
              frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
              frame.setBackground(Color.GREEN);
         // The main component.
         public static JPanel getMainPanel() {
              mainPanel = new JPanel();
              mainPanel.setBackground(new Color(0, 0, 255));
              mainPanel.setBorder(new EmptyBorder(new Insets(20, 20, 20, 20)));
              mainPanel.setLayout(new BorderLayout());
              mainPanel.add(getButton(), BorderLayout.NORTH);
              mainPanel.add(getAnimationPanel(), BorderLayout.CENTER);
              return mainPanel;
         // Switch button.
         private static JButton getButton() {
              JButton button = new JButton("Switch");
              button.addActionListener(new ActionListener() {
                   @Override
                   public void actionPerformed(ActionEvent e) {
                        switchToOpenGl();
              return button;
         // Do the switch.
         protected static void switchToOpenGl() {
              // Make the OpenGL overlay visible / invisible.
              if (!state) {
                   glCanvas.setVisible(false);
              } else {
                   glCanvas.setVisible(true);
              state = !state;
         // Normal swing panel with buttons
         public static JPanel getNormalPanel() {
              if (swingPanel1 == null) {
                   swingPanel1 = new JPanel();
                   for (int i = 0; i < 10; i++) {
                        swingPanel1.add(new JButton("Asdf" + i));
                   swingPanel1.setBackground(Color.black);
              return swingPanel1;
         // Extra panel container just for testing whether background colors show through.
         public static JPanel getAnimationPanel() {
              if (glPanel == null) {
                   glPanel = new JPanel(new BorderLayout());
                   glPanel.setBorder(new EmptyBorder(new Insets(20, 20, 20, 20)));
                   glPanel.setBackground(Color.YELLOW);
                   glPanel.add(getLayerFrame(), BorderLayout.CENTER);
              return glPanel;
         // A component that has two layers (panes), one containing the swing components and one containing the OpenGl animation.
         private static JInternalFrame getLayerFrame() {
              if (layerFrame == null) {
                   // Create a JInternalFrame that is not movable, iconifyable etc.
                   layerFrame = new JInternalFrame(null, false, false, false, false);
                   layerFrame.setBackground(new Color(155, 0, 0));
                   layerFrame.setVisible(true);     
                   // Remove the title bar and border of the JInternalFrame.
                   ((javax.swing.plaf.basic.BasicInternalFrameUI) layerFrame.getUI())
                             .setNorthPane(null);
                   layerFrame.setBorder(null);
                   // Add a normal swing component
                   layerFrame.setContentPane(getNormalPanel());
                   // Add the OpenGL animation overlay on a layer over the content layer.
                   layerFrame.setGlassPane(getGLCanvas());
              return layerFrame;
         // OpenGL component.
         public static GLCanvas getGLCanvas() {
              if (glCanvas == null) {
                   glCanvas = new GLCanvas();
                   glCanvas.setBackground(Color.CYAN);
              return glCanvas;
    }

    Oracle employees typically don't read these forums, you can report bugs here: http://bugs.sun.com/bugdatabase/

  • SetVisible(false) vs dispose()

    I am confused about something and need clarification. In my application I have several dialogs that open (setVisible(true)) when the user selects menu items to gather information. Since these dialogs are used over and over, my ok button calls dispose() to "hide" the dialog after each use. Is dispose() the correct method to use in this situation or setVisible(false)? But do what I want, but I really would like to know which is correct to use.
    Thanks

    When you call dispose() on a component, it completely kills the original reference, and as long as there are no other references to it, it becomes eligible for garbage collection. To get another one, you would have to create a new object.
    If you use setVisible(false), it simply hides the component, and can be shown again with setVisible(true). So it depends on what you want. if you call dispose() on it, you'll have to instantiate a new one if you want it back. If you don't want that (if you have to constantly reuse it), then simply call setVisible(false) when you don't want it, and call setVisible(true) when you do.
    Hope that helps,
    James

  • Problem with setVisible(false)

    I everybody!!
    I have a some panels in a JFrame, disposed ones underneath the others. But when I make one of the bottom invisble doing:
    jPanel.setVisible(false);
    the ones in the top becomes down!!
    Is there any way to avoid this?
    Thanks in advance

    If you have multiple panels sharing the same area in a JFrame then you should be using a [url http://java.sun.com/docs/books/tutorial/uiswing/layout/visual.html]Card Layout.
    Or you need to remove the old panel before adding the new panel.
    If you need further help then you need to create a [url http://homepage1.nifty.com/algafield/sscce.html]Short, Self Contained, Compilable and Executable, Example Program (SSCCE) that demonstrates the incorrect behaviour, because I can't guess exactly what you are doing based on the information provided.
    Don't forget to use the [url http://forum.java.sun.com/help.jspa?sec=formatting]Code Formatting Tags so the posted code retains its original formatting.

  • SetVisible(false) doesn't work with JDialog

    Hi evry one in this forum, i am using JDialog to get some inputs from user, when the user click on the ok button, i start processing and the JDialog must be invisible, for that i use myJdialog.setVisible(false) methode, but the JDialog is still visible, i may be use the wrong component or there is a problem.
    I write some thing like this:
    actionPerformed(){
    //getinputs and make some controls
    if(test){
    this.setVisible(false);
    //some traitments
    //some traitments
    }I think there is no thing wrong, not? what happen?

    I am sorry, this is some thing complicated:
    public class OpenKeyStore
        extends JDialog
        implements ActionListener, KeyListener, WindowListener {
      JPanel jPanel1 = new JPanel();
      Border border1;
      JLabel lprivateKey = new JLabel();
      JLabel lkeyPass = new JLabel();
      JTextField tkeyStorePath = new JTextField();
      JPasswordField tkeyPass = new JPasswordField();
      JButton bvalidate = new JButton();
      JButton bopenKeyStore = new JButton();
      JButton breset = new JButton();
      GridBagLayout gridBagLayout1 = new GridBagLayout();
      JFileChooser jfc = new JFileChooser();
      JOptionPane jop = new JOptionPane();
      private UploadParameters uploadParameters;
      private OpenRequest openRequest;
      private OpenResponse openResponse;
      private CheckCertRequest checkCertRequest;
      private CheckCertResponse checkCertResponse;
      private WaitBox waitBox;
      UploadApplet uploadApplet;
      public OpenKeyStore(Frame frame, String title, boolean modal) {
        super(frame, title, modal);
        try {
          jbInit();
        catch (Exception ex) {
          ex.printStackTrace();
      public OpenKeyStore(UploadApplet uploadApplet) {
        this(null, "", false);
        this.uploadApplet = uploadApplet;
      private void jbInit() throws Exception {
        uploadParameters = new UploadParameters();
        border1 = new EtchedBorder(EtchedBorder.RAISED, Color.white,
                                   new Color(148, 145, 140));
        this.setModal(true);
        this.setTitle("Ouvrir");
        jPanel1.setBorder(border1);
        jPanel1.setLayout(gridBagLayout1);
        jPanel1.setSize(400, 140);
        lprivateKey.setText("Cl� priv�e :");
        lkeyPass.setText("Mot de passe : ");
        bopenKeyStore.setActionCommand("openKeyStore");
        bopenKeyStore.setText("Ouvrir");
        bopenKeyStore.setMnemonic(KeyEvent.VK_O);
        bopenKeyStore.addKeyListener(this);
        bopenKeyStore.addActionListener(this);
        bvalidate.setActionCommand("bvalidate");
        bvalidate.setText("Valider");
        bvalidate.setMnemonic(KeyEvent.VK_V);
        bvalidate.addKeyListener(this);
        bvalidate.addActionListener(this);
        breset.setActionCommand("breset");
        breset.setText("R�etablir");
        breset.setMnemonic(KeyEvent.VK_R);
        breset.addKeyListener(this);
        breset.addActionListener(this);
        tkeyStorePath.setText("C:\\y.p12");
        tkeyStorePath.addKeyListener(this);
        tkeyPass.setText("y");
        tkeyPass.addKeyListener(this);
        this.getContentPane().add(jPanel1, BorderLayout.CENTER);
        this.getContentPane().setSize(410, 150);
        jPanel1.add(lprivateKey, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
            , GridBagConstraints.WEST, GridBagConstraints.NONE,
            new Insets(5, 5, 5, 5), 0, 0));
        jPanel1.add(lkeyPass, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0
                                                     , GridBagConstraints.WEST,
                                                     GridBagConstraints.NONE,
                                                     new Insets(5, 5, 5, 5), 0, 0));
        jPanel1.add(tkeyStorePath, new GridBagConstraints(1, 0, 1, 1, 10.0, 0.0
            , GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
            new Insets(5, 5, 5, 5), 150, 0));
        jPanel1.add(tkeyPass, new GridBagConstraints(1, 1, 1, 1, 10.0, 0.0
                                                     , GridBagConstraints.WEST,
                                                     GridBagConstraints.HORIZONTAL,
                                                     new Insets(5, 5, 5, 5), 200, 0));
        jPanel1.add(bvalidate, new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0
                                                      , GridBagConstraints.EAST,
                                                      GridBagConstraints.NONE,
                                                      new Insets(5, 5, 5, 5), 0, 0));
        jPanel1.add(bopenKeyStore, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0
            , GridBagConstraints.CENTER, GridBagConstraints.NONE,
            new Insets(5, 5, 5, 5), 0, 0));
        jPanel1.add(breset, new GridBagConstraints(2, 2, 1, 1, 0.0, 0.0
                                                   , GridBagConstraints.CENTER,
                                                   GridBagConstraints.NONE,
                                                   new Insets(5, 5, 5, 5), 0, 0));
        this.initFileChooser();
        this.tkeyStorePath.requestFocus();
        this.pack();
        Rectangle screenRect = this.getGraphicsConfiguration().getBounds();
        this.setLocation(
            screenRect.x + screenRect.width / 2 - this.getSize().width / 2,
            screenRect.y + screenRect.height / 2 - this.getSize().height / 2);
        this.show();
      public void actionPerformed(ActionEvent e) {
        if (e.getActionCommand().equals("openKeyStore")) {
          this.showOpenFileChooser();
          return;
        if (e.getActionCommand().equals("bvalidate")) {
          this.acte();
          return;
        if (e.getActionCommand().equals("breset")) {
          this.reset();
          return;
      public void keyPressed(KeyEvent e) {
        if (e.getKeyCode() == KeyEvent.VK_ENTER) {
          if (e.getSource() == this.bopenKeyStore ||
              e.getSource() == this.tkeyStorePath) {
            this.showOpenFileChooser();
            return;
          if (e.getSource() == this.bvalidate ||
              e.getSource() == this.tkeyPass) {
            this.acte();
            return;
          if (e.getSource() == this.breset) {
            this.reset();
            return;
      public void keyReleased(KeyEvent e) {}
      public void keyTyped(KeyEvent e) {
      private void initFileChooser() {
        jfc.setFileFilter(new javax.swing.filechooser.FileFilter() {
          public boolean accept(File f) {
            return (f.getName().endsWith(".p12") || f.isDirectory());
          public String getDescription() {
            return "(.p12) fichier key store";
        jfc.setDialogTitle("Selectionnez un fichier .p12");
        jfc.setMultiSelectionEnabled(false);
        jfc.setDialogType(JFileChooser.OPEN_DIALOG);
        jfc.setFileSelectionMode(JFileChooser.FILES_ONLY);
      private void showOpenFileChooser() {
        int returnVal = jfc.showOpenDialog(this);
        if (returnVal == JFileChooser.APPROVE_OPTION && jfc.getSelectedFile() != null &&
            jfc.getSelectedFile().exists()) {
          this.tkeyStorePath.setText(jfc.getSelectedFile().getAbsolutePath());
          this.tkeyPass.requestFocus();
        else {
          this.tkeyStorePath.requestFocus();
      private void reset() {
        this.tkeyStorePath.setText("");
        this.tkeyStorePath.requestFocus();
        this.tkeyPass.setText("");
      private void acte() {
    //waitBox = new WaitBox();
        openRequest = new OpenRequest();
        openRequest.setStorePath(this.tkeyStorePath.getText());
        if (!openRequest.isValide()) {
          jop.showMessageDialog(null,
                                "S.V.P v�rifiez le chemin de votre cl�!",
                                "Echec...", jop.ERROR_MESSAGE);
          this.tkeyStorePath.requestFocus();
          this.tkeyStorePath.selectAll();
          return;
        openRequest.setStorePass(new String(this.tkeyPass.getPassword()));
        openRequest.setReciverCert(this.uploadParameters.getReciverCert());
        OpenAction openAction = new OpenAction(this.openRequest);
        try {
          while (openResponse == null) {
            Thread.sleep(100);
            openResponse = (OpenResponse) openAction.getResponse();
        catch (Exception e) {
          e.printStackTrace();
        if (openResponse.getSenderPK() == null) {
          jop.showMessageDialog(null,
              "S.V.P entrez une cl� valide, \n ou verifiez votre mot de passe !",
              "Echec...", jop.ERROR_MESSAGE);
          this.tkeyStorePath.requestFocus();
          this.tkeyStorePath.selectAll();
          return;
        if (openResponse.getCaCert() == null) {
          this.setVisible(false);
          jop.showMessageDialog(null,
              "Votre cl� n'est pas valide.\n contactez votre administrateur!",
              "Echec...", jop.ERROR_MESSAGE);
          this.gotoPreviousPage();
          return;
        if (this.uploadParameters.getCipher() && openResponse.getReciverCert() == null) {
    this.setVisible(false);//*********************Does not work
    jop.showMessageDialog(null,
              "Vous ne disposez pas de certificat pour votre correspondant!",
              "Echec...", jop.ERROR_MESSAGE);
          this.gotoPreviousPage();
          return;
        this.setVisible(false);//*********************Does not work
        if (this.uploadParameters.getCipher()) {
          String compte;
          while (true) {
            compte = (String) JOptionPane.showInputDialog(
                this, "S.V.P. entrez le compte de votre correspondant : ",
                "Customized Dialog", JOptionPane.PLAIN_MESSAGE, null, null, "");
            if (compte == null) {
              //gotoprevious page
              return;
            this.checkCertRequest.setCommunName(compte);
            if (this.checkCertRequest.isValide()) {
              this.checkCertRequest.setReciverCert(this.openResponse.getReciverCert());
              this.checkCertRequest.setCaCert(this.openResponse.getCaCert());
              CheckCertAction checkCertAction = new CheckCertAction(this.
                  checkCertRequest);
              try {
                while (this.checkCertResponse == null) {
                  Thread.sleep(100);
                  this.checkCertResponse = (CheckCertResponse) checkCertAction.
                      getResponse();
              catch (Exception e) {
                e.printStackTrace();
              if (this.checkCertResponse.getReciverCertState()) {
                return;
              else {
                jop.showMessageDialog(null,
                    "L'identit� de votre correspondant n'a pas pu etre v�rifier!",
                    "Echec...", jop.ERROR_MESSAGE);
      public void windowActivated(WindowEvent e) {}
      public void windowClosed(WindowEvent e) {}
      public void windowDeactivated(WindowEvent e) {}
      public void windowDeiconified(WindowEvent e) {}
      public void windowIconified(WindowEvent e) {}
      public void windowOpened(WindowEvent e) {}
      public void windowClosing(WindowEvent e) {
        this.gotoPreviousPage();
      public void gotoPreviousPage() {
    }

  • Closing The JFrame without using setVisible(false)

    I am using a frame for creating table "public class createTable extends JFrame" this class is being used by two panels to display the data . in a last panel where I have put two buttons "ADD" for adding records to a access table and "RETURN" to return back , while closing the "createTable" frame.
    On Clicking the "RETURN" button the code :
    setVisible(false)
    just closes the buttons in the panel whereas the original frame doesnot hides. whereas, if i use an instance of createTable:
    private createTable ctbl;
    and the have it as
    ctbl.setVisible(false);
    exception is thrown . as well as the method :
    void remove(Container con) also throws exception and does not functions smoothly.
    Can anyone please help me>>>>

    The problem is probably that you're calling setVisible on the button, not on the frame.
    If you maintain a reference to the frame then just do something like this:
    frame.setVisible(false);If you don't then you'll need to work out which frame the button belongs to:
    SwingUtilities.getWindowAncestor(this).setVisible(false);Hope this helps.

  • 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?

  • After GLcanvas setVisible(false), normal JPanels sometimes not repainted.

    We are running an application which uses some jogl for animaties.
    Sometimes when the animation is finished and we set the GLCanvas to invisible, the normal
    java JPanels are not repainted.
    Also alt-tab to another windows application and back will not force a redraw.
    The application itself is still working, clicking on a (now) not visible button will trigger
    the jogl animations, and these are show correctly.
    Also from logging it appear that the AWT-thread is not blocking.
    We are looking for tips that can help find us the problem from logging
    as it only appears a few times a week and it is not reproducable.

    The problem is that most of the time it works, but after some hours/days, the java panels are not repainted.
    There is no memory leak.
    Pseudo code:
    public class AnimateTilePopup extends JPanel {
    GLCanvas glCanvas;
    public AnimateTilePopup() {
    super(null);
    setOpaque(true);
    glCanvas = new GLCanvas();
    glCanvas.setLocation(0,0);
    glCanvas.setSize(width, height);
    glCanvas.setVisible(false);
    glCanvas.setFocusable(false);
    add(glCanvas);
    flipRendererZoom = new AnimateRendererZoom();
    glCanvas.addGLEventListener(flipRendererZoom);
    public startAnimation() {
    glCanvas.setVisible(true);
    this.setVisible(true);
    public stopAnimation() {
    glCanvas.setVisible(false);
    this.setVisible(false);
    So sometimes when we call stopAnimation(), the animation is stoppped, but the underlying java JPanels are not repainted.
    When we now call startAnimation, the animation is shown and when stopped, no repaint for the normal JPanels.
    Most times it is working perfectly, only sometimes it failes.
    What can be the cause or what logging can be gather that might gives us a clue how to fix this problem.

  • Which event will be fired when I after set JFrame.setVisible(false)

    Experts.
    I want to know which event will be fired when I after set JFrame.setVisible(false)?
    Because I need to check a thread is finished it job or not.
    I have checked windowClosing event, but it doesn't work.
    Thanks
    Francis

    Oh....
    Sorry, I find it will fired on componentHidden event.
    Very sorry.

  • Difference between false and Boolean.FALSE ?

    Hello,
    can you please tell the difference between false and Boolean.FALSE ?

    The trap behind autoboxing is that things work just fine when at least one side of the equation is a primitive. Things turn out unexpected when all of a sudden both sides of the equation happen to be an object:
    public class Test {
         public static void main(String[] args){
              boolean bp = false;
              Boolean bo = new Boolean(false);
              Boolean bo2 = new Boolean(false);
              System.out.println("Primitive VS Boolean.FALSE: " + (bp == Boolean.FALSE));
              System.out.println("Primitive VS new object: " + (bp == bo));
              System.out.println("New object VS Boolean.FALSE: " + (bo == Boolean.FALSE));
              System.out.println("new object vs new object 2: " + (bo == bo2));
    }Result:
    Primitive VS Boolean.FALSE: true
    Primitive VS new object: true
    New object VS Boolean.FALSE: false
    new object vs new object 2: falseTry explaining that in the context of this thread without ever referring to autoboxing specifically. Remember that people find these posts through Google, if you pass out information while hiding the gritty details, it gets confusing.

  • 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"

  • 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.

  • My ipod touch is not recognized and a "false" recovery mode icon is diplayed on ipod

    hello, sorry for the long title its just that i find this problem very specifically tied to me and probably ten other people on this planet... Since i couldnt find an answer on google or youtube....
    now im here, newly created an apple account, and i wish to ask other people..... why?
    i have received an ipod from a buddy of mine who finds me more computer-knowledgeable than he is.... which is a strech to say, anyways: problem is, ive done EVERYTHING, and not just everything, but EVERYTHING, unistall and re-install of itunes, including the recovery and DFU modes, driver updates, other computers, new cables, and even trouble shooting with every possible/relevant trouble shooter there is.... and it all leads to the same promblem:
    Windows 7 says: "device not recognized"
    oh, and about the "false" recovery mode, i found this out by carefully watching the ipod start up and i noticed that the top status bar turns on, then quickly off.... and the battery symbol remaines.... i also figured out the real recovery mode and already tried the whole "itunes restoration" routine.... but it doesnt matter because:
    Windows 7 says: "device not recognized"
    so, afterwards i figured "hey, maybe its got something to do with the drivers?" well, there was my solution, so i went to device manager, and attempted to update said driver manually using the Apple Moble Manager Service drivers... *GASP* DID IT WORK?
    Windows 7 says: "Driver Manager says:'error: code 10: device will not start.'"
    ah yes... what is code 10? its a code that aplies only to a device that has given an error code that windows does not recognise.... i assume the ipod thinks its already up-to-date.... or maybe its just crying in its digital coma, "just five more minutes, mommy!"
    so final question, probably the only question i want answered, if any:
    How, If possible, Do I get passed this "code 10" error so i can update my driver, and finaly cure my ipod of this..... coma?

    Device Not Recognised
    For PC
    http://support.apple.com/kb/TS1538
    For Mac
    http://support.apple.com/kb/ts1591

  • Anyone attempt to download PHOTOSHOP ELEMENTS v12 and got false error messges and crashes?

    I had to download Premiere Elements v12 and Photoshop Elements v12. Premiere Elements went fine but Photoshop Elements gave me false error messages about disk space and user access. Anyone else have this problem?

    right click the installation file and click 'run as administrator'.

Maybe you are looking for

  • How can I replace an existing report?

    The way our Enterprise server is setup, we have a folder that we publish all reports to. This folder is proteced from view from anyone but admins. In order for our users to "see" a report we create a shortcut of the report in their User folder. This

  • Master Detail with Search

    Hi All, I have created a Master (Form with Navigation buttons) - Detail (table) with search region. Intially both regions show no data as expected. When I search for an entry in Master region - It shows the data in Master but not in Details region. W

  • Balance Dimensions

    Hi, We are impelmenting HRMS&Payroll Rel1.02. This is not UK or US install. It is a Global Install 1. The Pay advice Report does not show up the Deductions. The Earnings and Total Pay comes up. How do we get the Deductions on the Pay Advice 2. How do

  • Budget Question - negative assigned value

    Hi FI experts, We have IM module deployed in our system and we use WBS elements for budget tracking purposes only. A project  was created in 2009 with WBS element, say WBS09, which was assigned certain budget. In the same year there were some expense

  • SAP IS Banking- Time Deposits

    Dear Experts, I am configuring a Time Deposit Product in SBS 7.0. As per the requirement, there is an early withdrawl penalty to be calculated if the deposit is withdrawn before the maturity date. The calculation is possible in SBS 7.0. However, the