Partage
  • Partager sur Facebook
  • Partager sur Twitter

[JAVA] annuler la fermeture de la fenêtre

appuye sur la croix ...

    23 novembre 2006 à 22:13:58

    Bonjour, j'aimerais savoir comment empêcher la fenêtre de disparaitre lors de l'appuye sur la croix.

    ? merci
    • Partager sur Facebook
    • Partager sur Twitter
      23 novembre 2006 à 22:46:18

      Avec la méthode setDefaultCloseOperation() et DO_NOTHING_ON_CLOSE.
      http://java.sun.com/j2se/1.3/docs/api/javax/swing/JFrame.html#setDefaultCloseOperation(int)
      • Partager sur Facebook
      • Partager sur Twitter
        24 novembre 2006 à 3:19:17

        Et si tu veux qu'une fenêtre apparaisse te demandant si tu veux vraiment quitter :


        addWindowListener(new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
                int exit = JOptionPane.showConfirmDialog(null,"Êtes-vous sûr de vouloir quitter?","Quitter?",JOptionPane.YES_NO_OPTION);
                if (exit == JOptionPane.YES_OPTION)
                System.exit(0);
          }
        } );


        (le code doit etre dans un JFrame, ou un Frame)
        • Partager sur Facebook
        • Partager sur Twitter
        Altarapp.com - Applications, Code Snippets, API Wrappers et etc, le tout en C# le plus clair du temps!
          24 novembre 2006 à 7:03:52

          Justement j'utilise les listener, mais des que je clique sur la croix, même si je ne mais pas System.exit(0), la fenêtre se ferme.
          Mais il tourne encore ...

          comment donc faire pour remédier a ce problème...
          • Partager sur Facebook
          • Partager sur Twitter
            24 novembre 2006 à 9:55:36

            C'est normal, la fenetre se cache par default.
            Tu peux changer avec le setDefaultCloseOperation.

            Citation : Doc java


            Sets the operation that will happen by default when the user initiates a "close" on this frame. You must specify one of the following choices:

            • DO_NOTHING_ON_CLOSE (defined in WindowConstants): Don't do anything; require the program to handle the operation in the windowClosing method of a registered WindowListener object.
            • HIDE_ON_CLOSE (defined in WindowConstants): Automatically hide the frame after invoking any registered WindowListener objects.
            • DISPOSE_ON_CLOSE (defined in WindowConstants): Automatically hide and dispose the frame after invoking any registered WindowListener objects.
            • EXIT_ON_CLOSE (defined in JFrame): Exit the application using the System exit method. Use this only in applications.



            The value is set to HIDE_ON_CLOSE by default.



            Si tu ne comprends pas l'anglais, en gros ca dit que l'action HIDE_ON_CLOSE est l'action par defaut, donc la fenetre se cache quand tu cliques sur la croix.
            Utilise DO_NOTHING_ON_CLOSE comme va leur pour que la fenetre ne se ferme pas.
            • Partager sur Facebook
            • Partager sur Twitter
              24 novembre 2006 à 11:34:32

              Ca peut être utile de lire les réponses :D
              • Partager sur Facebook
              • Partager sur Twitter
                24 novembre 2006 à 16:42:57

                Désolé :), mais je comprend mal l'anglais :(.
                merci a vous
                • Partager sur Facebook
                • Partager sur Twitter

                [JAVA] annuler la fermeture de la fenêtre

                × Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
                × Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
                • Editeur
                • Markdown