Close a fram

i want to close a frame after i click a button... i have the button setup and added an action listener to it then i perform the functions i need performed but after everything is done i would like to exit or close the entire frame... how can i do that?

<implement beatnik>
uh... OP question I am assuming has to do with :
myFrame.setVisible(false);//hides frame
myFrame.dispose();//prepares frame for disposal - doesn't actually dispose as you could call setVisible()
myFrame = null;//kill your reference.
System.gc();//cross your fingers and hope like hell that the GarbageCollecter gets the message... all better ?
:)

Similar Messages

  • Close a Frame when another one opened

    How do i Close a frame (dependent Frame) when another frame opened
    dispose() method did nothing and so do system.exit(0); as the System.exit(0) close the whole app that meant also the frame i would like to open when the other frame closed and moved from " Memory " huge topic for me
    dispose(); didn't do what i really needed to happened
    please any suggestions ASAP ? i need that in swing app

    i used dispose() but didn't work with me as i noticed the memory usage with this java app when i run the app after closing the frame . the memory usage didn't change that meant as least the frame didn't closed or cleared from the memory ?!
            try {
                    Socket ss = new Socket("14.23.5.122", 1235);
                  //  JOptionPane.showMessageDialog(null, "Server's OK", "Connection", JOptionPane.INFORMATION_MESSAGE);
                    new LoginFrame().setVisible(true);
                  //  this.dispose();
                    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                } catch (UnknownHostException eh) {
                    System.out.println("Unknow Host Exception"+ eh.getMessage());
                } catch (IOException eo) {
                    System.exit(0);
                   System.out.println("IO Exception"+ eo.getMessage());
             /*finally{
            System.exit(0);
            }*/

  • Close a frame

    Hi.
    Instead of exit the application at the line System.exit(0); I just want to close the frame or hide it.
    I have tryed with the lines that are commented, but it didn't work.
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class PaginaPrincipala extends JPanel implements ActionListener {                               
        private static String EXIT = "exit";
        private JFrame controllingFrame;
            public static String user;
            JPanel panel;
            //JFrame f;
        public static void FereastraPrincipala(String inUser) {
             user = inUser;
            JFrame.setDefaultLookAndFeelDecorated(true);
            JFrame frame = new JFrame("PaginaPrincipala");       
            frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
            final PaginaPrincipala newContentPane = new PaginaPrincipala();
            newContentPane.setOpaque(true);
            frame.setContentPane(newContentPane);
            newContentPane.ContinutPaginaPrincipala(frame);
            frame.addWindowListener(new WindowAdapter() {
                public void windowActivated(WindowEvent e) {
                    newContentPane.resetFocus();
            frame.pack();
            frame.setExtendedState(frame.MAXIMIZED_BOTH);
            frame.setVisible(true);
            frame.toFront();       
            //f = frame;    
        public void ContinutPaginaPrincipala(JFrame f) {
             panel = new JPanel();         
             GridLayout layout = new GridLayout(5, 2, 5, 5);
              panel.setLayout(layout);
              JTextField campTempUser = new JTextField(20);
              JButton butonExit = new JButton("Exit");
            butonExit.setActionCommand(EXIT);
            butonExit.addActionListener(this);
              add(panel);
              panel.add(butonExit);                          
        public void actionPerformed(ActionEvent e) {
            String cmd = e.getActionCommand(); 
            if (LOGIN.equals(cmd)) {              
            if (EXIT.equals(cmd)) {
                 InregistrareLaInchidereaAplicatiei inregistrareLaInchidereaAplicatiei = new InregistrareLaInchidereaAplicatiei();
                inregistrareLaInchidereaAplicatiei.InregistrareInDB(user);
                 System.exit(0);     
              //frame.setVisible(false);
    }

    "And if he still doesn't answer ?"
    Yes, I have tried, but it still doesn't work. And I feel that it must be so simple.
    When I click the Exit button, the frame must disappear.
    Here is the code with the main function:
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class PaginaPrincipala extends JPanel implements ActionListener {
        private static String EXIT = "exit";
        private JFrame controllingFrame; //este nevoie pt dialoguri.
            public static String user;
            JPanel panel;
            JFrame f;
       public void FereastraPrincipala() {
             //user = inUser;
            //setari pt grafica ferestrei.
            JFrame.setDefaultLookAndFeelDecorated(true);
            //creeaza si seteaza fereastra.
            JFrame frame = new JFrame("PaginaPrincipala");      
            frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
            //creeaza si seteaza 'content pane'.
            final PaginaPrincipala newContentPane = new PaginaPrincipala();
            newContentPane.setOpaque(true);
            frame.setContentPane(newContentPane);
            newContentPane.ContinutPaginaPrincipala(frame);
            //seteaza focusul pe 'content pane'.
            frame.addWindowListener(new WindowAdapter() {
                public void windowActivated(WindowEvent e) {
                    newContentPane.resetFocus();
            //Afiseaza fereastra.
            frame.pack();
            frame.setExtendedState(frame.MAXIMIZED_BOTH);
            frame.setVisible(true);
            frame.toFront();      
            f = frame;
        public void ContinutPaginaPrincipala(JFrame f) {
             panel = new JPanel();         
             GridLayout layout = new GridLayout(5, 2, 5, 5);
              panel.setLayout(layout);
              JTextField campTempUser = new JTextField(20);
            //Butonul 'EXIT'
            JButton butonExit = new JButton("Exit");
            butonExit.setActionCommand(EXIT);
            butonExit.addActionListener(this);
              add(panel);
              panel.add(butonExit);                          
        public void actionPerformed(ActionEvent e) {
            String cmd = e.getActionCommand();       
            //daca se apasa EXIT se sterge userul din DB-ul cu userii activi si se iese din aplicatie
            if (EXIT.equals(cmd)) {
                 //System.exit(0);
                 Toolkit.getDefaultToolkit().beep();     
                 f.setVisible(false);
        public static void main(String args[]) {
             PaginaPrincipala fer = new PaginaPrincipala();
             fer.FereastraPrincipala();
        //Muta focusul pe campul de user.
        protected void resetFocus() {
            //campLogin.requestFocusInWindow();
    }

  • How to close all frames in a page?

    friends..
    im having a html page(test.html) which has 3 frames.
    in one frame im having BACK button which takes me to the
    default page.
    But the problem is, when i click BACK button it loads the default.html in same frame itself...i want to open default.html as complete page..
    help out me...

    Have not tested this ..but I would suggest you to try something close to this ...
    <input type="button" name ="xyz" value="BacK"
    onClick="javascript: parent.framename.window.href='/default.html'">Change the 'framename' to the one you have assigned.
    Hope it works ..else research on the above lines only
    -Rohit

  • Disable "Close" in Frames

    How am I able to disable the "Close" icon located at the top-right corner of a Frame?
    Cos I do not want the user to click that icon
    thanks

    Thanks for your advice. I know of that one. Just that it's a bit confusing to the users. What I want is that the "Close" button is DISABLED, so that users cannot click on the button.

  • WindowClosing doesn't completely close a frame

    I wrote a simple command line application that needs to prompt for a username and a password. Since the characters are always echoed in Java, the alternative way to do this is to call a GUI with a password-textfield. I am able to obtain the login credentials, and to dispose of the login pop-up window, but the program doesn't return unless I hit Ctrl+C.
    Calling System.exit(0) does the job but not quite. I was hoping whether there is a way to completely destroy the Login GUI without having to warn the user of this class to call System.exit(0) each time the Login box is used. Most of the times the user doesn't even know that this class is called.
    Is there any dispose, exit, close or whatever method that does this?
    (It could be any of the classes: javax.swing.JDialog, java.awt.Frame etc.)

    The goal is to totally get rid of the GUI threads still running on the background, not to just set the visibility to false. However, thanks to your code, with a couple of modifications, I figured out the solution.
    I read the workaround in some other topic:
    How to kill AWT-Windows thread - submitted on Dec 14, 2000.
    If I set the window to null it does what I want.
    Thanks!
    import java.awt.*;
    import java.awt.event.*;
    public class temp {
    public static void main(String args[]) {
    ClosingWindow w = new ClosingWindow();
    w = null;
    class ClosingWindow extends Frame implements WindowListener {
    public ClosingWindow() {
    this.setTitle("temp frame");
    this.add(new Label("Hit the close button!"));
    this.addWindowListener(this);
    this.setSize(400,200);
    this.setVisible(true);
    //Here are the event catchers
    public void windowActivated(WindowEvent e) { }
    public void windowClosed(WindowEvent e) { }
    //This should clear up your window
    public void windowClosing(WindowEvent e) {
    setVisible(false);
    dispose();
    public void windowDeactivated(WindowEvent e) { }
    public void windowDeiconified(WindowEvent e) { }
    public void windowIconified(WindowEvent e) { }
    public void windowOpened(WindowEvent e) { }

  • Close gui frame on cancel button

    why does it close even when I press submit?
        public void actionPerformed(ActionEvent e){
            if(e.getActionCommand().equals("Cancel"));{
                System.exit(0);}
            if(e.getActionCommand().equals("Submit"));{
            System.out.println(login_txt.getText());
            System.out.println(pass_txt.getPassword());}
                }

    You have a ";" at the end of the if statement. The code should be:
    public void actionPerformed(ActionEvent e)
    //    if(e.getActionCommand().equals("Cancel"));
        if(e.getActionCommand().equals("Cancel"))
            System.exit(0);
    //    if(e.getActionCommand().equals("Submit"));
        if(e.getActionCommand().equals("Submit"))
            System.out.println(login_txt.getText());
            System.out.println(pass_txt.getPassword());}
        }

  • Problem to close a Frame(not) JFrame...

    public void windowClosing(WindowEvent e) {
    System.exit(0);
    I use this method but my frame window is not closing...Plz help

    if u extends JFrame then add this code
      addWindowListener(new WindowAdapter(){
                public void windowClosing(WindowEvent e) {
                    if(JOptionPane.showConfirmDialog(null,"Are you sure to  exitt!","Confirmation",JOptionPane.YES_NO_OPTION,JOptionPane.WARNING_MESSAGE)==0){
                        dispose();
                        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                        System.exit(0);
                    }else{
                        setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
            });

  • Terminate thread when frame closes

    I made a JFrame which runs a thread, but when I close the frame it goes on running... I can't stop it unless I ctrl-alt-del.. How do I terminate it? I start it by calling start(), should I use run() instead?
    (I'm scared to try since it f***s my pc up, so I would rather ask a knowledgeable person first) here's the related part of the code:
              public void run(){
                   Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
                   while(true){
                        player.playerMove();
                        // repaint
                        repaint();     
                        // end of while
                        try
                             Thread.sleep (speed);
                        catch (InterruptedException ex)
                             // do nothing
                        Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
              public void start(){
                   Thread th = new Thread(this);
                   th.start();
              }Message was edited by:
    nayon_7

    notice that the way you create threads is quite unique
    actually, for what you want to do, start method should not be overriden, you should create an instance of your class and call "start" on the instance ; that's all
    "new Thread(this)" is just... ODD! :p

  • Opening and closing a frame from an applet security problem

    can I open a frame or a window from an applet and close the frame by using
    System.exit(0) for the frame or will it throw a security problem.

    I am using system.exit(0) to exit the JVM.
    dispose()
    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.
    If this frame have to be close and open again don't use dispose.
    there is no check whether a frame is active? what you can do is set the the new frame to null (frame = null) and also when you dispose it, this will let you know if the frame is active or not.
    Noah

  • Can't figure out how to add bars to reformat 16:9 video to fit a 4:3 frame

    Hi all, I'm a long-time user of iMovie 5, and a professional Avid video editor. On my home computer, however, I have some serious issues using the "dumbed down" version of iMovie '08 which, unfortunately, it seems I must use if I want to avoid purchasing new software, and don't feel like trucking my personal work to the office.
    Usability issues aside, I'm at a total loss as to how to reformat my imported video clips. At the moment I have a .dv file which is exported from FCP in a 16:9 format. I want to take this into iMovie '08, format it to fit a 4:3 window, add it to a bunch of other clips, and export a finished 4:3 movie to then put on DVD.
    Importing is fine, editing is meh but works (sorry, I'm a snob), and exporting works fine, but I can't for the life of me figure out how to put a reformat on the video. The goal is to have black bars on the top and bottom of the video image, squeezing the anamorphic 16:9 video down so that people don't look vertically stretched in a 4:3 window.
    What I do NOT want to do is crop out any of the video footage. The goal is to keep all of the video, and just add the black to the top and bottom in order to make it look, well, normal. For the life of me, I can't figure it out. it looks like this would be something that the Crop / Fit tool does, but that won't let me extend the fit outside of the frame of the video, nor will it let me put a 16:9 fit inside of the 4:3 viewing window (I only have a 4:3 option when in 4:3 mode, and only have a 16:9 option when in 16:9 mode).
    Thank you very much for your insight.
    PS: Just as an aside, why on earth did apple move iMovie '08 away from timeline-based editing? The old iMovie versions were quite powerful editing suites in their own right - even with limited video and audio layers. The '08 version seems to just hate users who want to do anything remotely close to frame-specific edits.

    I guess I've got to add the flags back in somehow? The weird thing is that the movie is the correct aspect ratio in iTunes and Quicktime, just not iMovie '08.
    iTunes, QT Player, and previous versions of iMovie all relied on the "Current Display Size" setting to set the aspect ratio. (I.e., you can modify this setting and change the aspect ratio by merely changing the display size in QT Pro and re-saving the file for these apps.) Unfortunate, iMovie '08 looks for the flag for the main display/export, and, if Apple hasn't changed things, uses the "current display size" to set the aspect ratio of the thumbnails... Weird.
    How would I add those flags back in? Can I just open in quicktime and save a new copy? Or am I going to have to contact the original source of the material and have him export it again (with different settings? And what settings would those be? He's coming from FCP).
    If the content is of exceptional quality, you could try re-exporting it in MPEG Streamclip using the "Export to DV..." option. This will re-flag the file with the aspect ratio you select in the export window. Also, be advised that performing destructive edits in iMovie '08 that forces the data to be re-written to new containers will lose the flag in the process unless Apple has made some recent changes to avoid this.

  • Frame 9 solution for table column + side head does not work in Frame 10 and 11

    In Frame 9 structured (DITA) we could force Frame to record the actual widths of table columns in the DITA XML.  Frame 9 would respect the widths when opening the file.  This was particularly useful for forcing tables to be wide -- to go across the column and the side head -- and for the columns to never resize. 
    In Frame 9 this was done by commenting out the line
    "writer use proportional widths;" 
    like this
    "/* writer use proportional widths; */"
    in the topic.rules.text" file located in
    "...\FrameMaker9\Structure\xml\DITA\app\DITA-Topic-FM"
    This no longer works in Frame10 and Frame 11.  Even though the same line is commented out in all the "NAME.rules.txt" files in all the subdirectories of
        "...\AdobeFrameMaker11\Structure\xml\DITA_1.2\app"
    and
        "...\AdobeFrameMaker11\Structure\xml\DITA\app"  
    and
        "...\AdobeFrameMaker10\Structure\xml\DITA_1.2\app"
    and
        "...\AdobeFrameMaker10\Structure\xml\DITA\app"  .
    Commenting out the line does force Frame 10 and 11 to record  the absolute column width (2.357" etc.) in the DITA XML.
    However, on Open,  Frame 10 and 11 force the table to fit in the column, not the column and sidehead. That is they behave as though they were still using proportional column widths.  It seems the original values (as inserted by Frame 10 and 11 before closing!) are recalculated on Open, thereby mimicking the default proportional width behavior.  
    For example, this on Save then Close from Frame 10 or 11
    <table frame = "topbot" colsep = "0" rowsep = "1">
    <tgroup cols = "4" colsep = "0" rowsep = "1" outputclass = "FormatB">
    <colspec colnum = "1" colname = "1" colwidth = "1.796in" colsep = "0"/>
    <colspec colnum = "2" colname = "2" colwidth = "1.852in" colsep = "0"/>
    <colspec colnum = "3" colname = "3" colwidth = "1.179in" colsep = "0"/>
    <colspec colnum = "4" colname = "4" colwidth = "2.152in" colsep = "0"/>
    goes to this on Open then Save: 
    <table frame = "topbot" colsep = "0" rowsep = "1">
    <tgroup cols = "4" colsep = "0" rowsep = "1" outputclass = "FormatB">
    <colspec colnum = "1" colname = "1" colwidth = "1.351in" colsep = "0"/>
    <colspec colnum = "2" colname = "2" colwidth = "1.393in" colsep = "0"/>
    <colspec colnum = "3" colname = "3" colwidth = "0.887in" colsep = "0"/>
    <colspec colnum = "4" colname = "4" colwidth = "1.618in" colsep = "0"/>
    Any help at all would be appreciated!  
    We have 8,000 to 10,000 pages to PDF in the next few days and about 33% of those pages are messed up tables!
    Message was edited by: borealforest

    Hi...
    Unfortunately, I don't have any insight into the default DITA table handling in FM10 or FM11 .. so can't give you the answer you're looking for. Since both FM10 and FM11 offer ExtendScript, you could write a script (or have one written) that processes all of your files to reset the table widths. Or, perhaps the best short term solution may be to reinstall FM9 to get the job done, then spend more time later to figure out a better solution.
    One alternative would be for you to use DITA-FMx, which supports the table/@pgwide attribute for controlling which tables span the page and which don't. Since your tables probably don't make use of this attribute, it won't help in the near term, but might make sense going forward.
    Cheers,
    Scott Prentice
    Leximation, Inc.
    www.leximation.com

  • Problems with disposing frames

    im developing a GUI which, opens up a new frame when u press a button called 'control panel', in this new frame theres a button called 'connect' i use it to connect to a remote server, when its connected the server, the button is changed to 'disconnect' which obviously disconnects from the server. BUT when i close this control panel using the 'dispose()' method, and then when i open another instance of it, and press the disconnect button, it disconnects and automatically connects again (calling the action method twice) this is because there are 2 instace of the control panel open and i do not know how to fully delete and instance of one, it will keep happening for how many instance of control panel are open, e.g if i open and close the control panel 7 times, and press it connect/disconnected button it will loop 7 times. SO is there a way instead of using 'dispose' to completely delete an instance of a frame.
    thanks

    so what do u guys think i should do, how can i make it only have once instance of an actionListener despite the fact it could be opened and closed x ammount of times and it will do the action x times....
    some code...
    MainFrame (holds the button which opens the new frame)
      void procSettings_actionPerformed(ActionEvent e)
        procSettings s = new procSettings();
        s.setTitle("Processor Load Control Panel");
        s.setSize(370, 467);
        s.setLocationRelativeTo(null);
        s.setResizable(false);
        s.setVisible(true);
      }ProcSettings (frame with the disconnect / connect button)
      void line1Activate_actionPerformed(ActionEvent e)
        if(!MainFrame.procActive1)
          //connect
          Parser.connect1(line1SelectRNC.getSelectedItem(), "tch" + MainFrame.rncList[line1SelectRNC.getSelectedIndex() - 1][1]);
          line1Activate.setText("De-Activate");    // Changes the button to be a disconnect button
        else
          //disconnect
          Parser.disconnect1();
          line1Activate.setText("Activate");    // Changed the button to be a connect button
      }Now this connect fine the firs time, then i press the 'done' button (code below) which closes this frame and return to the program which carrys out the other functions. When I return to disconnect, I open another instance of ProcSettings and then i press De-Activate, its disconnects, then connects immediatly again (goes through the action method twice since the frame has been opened twice and this will continue for how many times the frame has been open)
    heres the done button in the ProcSettings
      void settingsDone_actionPerformed(ActionEvent e)
        dispose();
      }cheers for ur help guys...

  • How do I stop the Close Operation of JFrame

    I want to stop user to close my frame on click of window close icon. How do I stop this operation.
    Dinesh

    Hi,
    Just add this in ur code
    setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);

  • I can't close my swing form ...

    I have a JFrame swing GUI - how do I exit the app ?
    How do I display a popup box with a message ? or question ?
    thanks !
    Craig

    To close the frame, in the constructor, add:
    addWindowListener(new WindowAdapter() {
    public void windowClosing(WindowEvent evt) {
    System.exit(0);
    To pop up a prompt, add this when you click, say, "Exit" from a menu or button:
    int ans = JOptionPane.showConfirmDialog(this,"Do you want to exit the application?", "ExitDialog", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
    if (ans == JOptionPane.YES_OPTION)     {
    System.exit(0);
    }

Maybe you are looking for

  • Best Buy "HOLDS" 2X the authorized amount on a Debit Card?

     My bank just alerted me to having 2 charges for a single purchase from Best Buy - it was a portable ac.  My online account already shows both charges deducted. I call customer service and the first rep tells me - only one charge was authorized - not

  • SAP RFC SDK 7.10 Compilation Issues

    Hello , We have a Pro*C program that is using the RFC SDK 7.10 When we are compiling our program with Pro*C Compiler in HP UX 11iv2 os we are getting the following errors: SAP_U16_PROTOTYPE_STDC(mkstemp)..1 PCC-S-02201, Encountered the symbol "mkstem

  • Can't finish importing photos from iPhone to iPhoto

    I have about 2,000 pictures in my iPhone 4. When I try to import my photos from iPhone to iPhoto Library, it stops importing after about 250 photos. Keeps saying 1,489 remaining(something like that) photos and the picture image on your iPhoto stops o

  • I want all my videos to play through one player, instead of having multiple videos!!

    I would like to embed a video player into a PDF.  I would like to have links in my document that, when clicked will trigger different videos to play in the ebedded video player.  So In other words, I would like to have 5 videos on one page, but I wan

  • My call reject can't work in iPhone 5

    Hi, My call reject can't work in iPhone 5..!! I can't even c the icon( to swap up) when incoming call.