Intercepting user closing JInternalFrame

I need to show a confirmation dialog, and do some cleanup, when a user clicks the "X" on a JInternalFrame. How is this done?
Thanks! --- Eric

make your internal frame implement InternalFrameListener, then add that listener to your internal frame. The InternalFrameListener will need you to implement the following methods:
public void internalFrameOpened(InternalFrameEvent e){
public void internalFrameClosed(InternalFrameEvent e){
public void internalFrameClosing(InternalFrameEvent e){
public void internalFrameActivated(InternalFrameEvent e){
public void internalFrameIconified(InternalFrameEvent e){
public void internalFrameDeiconified(InternalFrameEvent e){
public void internalFrameDeactivated(InternalFrameEvent e){
}Try putting what you need in the internalFrameClosing() method.

Similar Messages

  • Problem closing JInternalFrame without first activating it

    Hi all,
    In my app when user clicks a button in JInternalFrame A, JInternalFrame B pops up, so I want to close JInternalFrame B when user close JInternalFrame A.
    I put the routine in JInternalFrame A's closing event. Everything works fine if the user click anywhere in the JInternalFrame A first then clicking the close button. But the problem shows up when the user directly clicking the close button without activating the frame first, this time the closing event is not called. Is this the default behaviour or is this a bug ?
    Any help would be greatly appreciated.
    Setya

    OK....you can do that.  I would recommend the GSM version (AT&T), but you can buy it here and activate there.  Lot's of people do.......

  • Intercept window closing or quitting

    I need to bring up an alert to potentially intercept user from closing a document window or quitting the application.
    I found a sample code called DocWatch but it only seems to do notification, but I have no way to intercept the action and potentially stop the user action.
    Any info is greatly appreciated.
    pete

    I found the CustomActionFilter in CS1 SDK actually have an example to handle the close command, so I copied the code into CS3 SDK and sure enough, it works!
    // (3) filter the "File >> Close" menu
    ActionFilterHelper filterCloseAction;
    filterCloseAction.SetFilterActionID(kTrue, kCloseActionID, kCloseActionID, kTrue);
    filterCloseAction.SetFilterActionName(kTrue, PMString("&Close"), PMString("test - Close"));
    filterCloseAction.SetFilterComponentClass(kTrue, kDocumentComponentBoss, kCstAFltActionComponentBoss);
    gActionFilterHelpers.push_back(filterCloseAction);
    There's is an issue...the sample code does not intercept when the user clicked on the close box (this is on a Mac, the red button at the upper left corner).
    In addition, the CS1 sample code does not work on the "Quit" command, either... I want to be able to abort the quit (base on a reply from a dialog of mine).
    Thanks.

  • The user closed the browser while still connected

    hello
    Like when using regular internet site, the user can at any moment close the browser withoug logging out. In this case, the JDBC connection will remain open (i guess until the session timesout), is there a way to handle these open session and close them to release the session from the database
    regards

    dear sir..
    when you deploy the Application into an oracle application server, specify the DataSource for it, There you will find in addition to connection details some timer settings specifying how many seconds the server waits on idle connections before closing them.
    regards

  • How to handle event when the user closing the browser (Urgent Please)

    Hi,
    How to handle the event when user closes the browser....
    i want to display some alter message when user trying to close the browser...
    Please can any one help me how i have to do this...........
    Thanks.

    Finally got this working. You cannot use the stop() or destroy methods. By the time they are called all database connections are gone and you will get a null pointer exception.
    You will have to use the onBeforeUnload method in the html file that calls the applet and use JavaScript to call the save method in java which saves the document:
    <SCRIPT LANGUAGE="JScript" TYPE="text/javascript">
    function Save()
    //i call the applets doSave() method from here in which i save all
    //changes to the database
    top.Tree.document.TestApplet.doSave();
    //this will invoke the default IE message for closing the window
    //when user clicks on the x in the browser
    message = "Your document has been saved."
    return message;
    window.onbeforeunload=Save;
    </SCRIPT>
    //the applets doSave()
    public void doSave()
    //this frame provides user with the message that document is being
    //saved
    final JFrame frame = new JFrame("Saving");
    JPanel contentPane = new JPanel();
    JLabel label = new JLabel(" Please wait, saving document...");
    frame.getContentPane().add(label,BorderLayout.CENTER);
    frame.setSize(250, 100);
    frame.setLocation(300, 400);
    frame.setResizable(false);
    frame.setVisible(true);
    frame.addWindowListener(new WindowAdapter()
    //the frame is just for user's information, so prevent user from
    //closing it or iconifying it.
    public void windowClosing(WindowEvent e)
    frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    public void windowIconified(WindowEvent e)
    frame.setState(frame.NORMAL);
    //call my saveDocument() method that saves everything to the database.
    editorModule.saveDocument();
    //System.out.println("finished calling saving document");
    //once the saving is done the frame with the message disappears
    frame.setVisible(false);
    //System.out.println("setting frame to false");
    //I also had an exit button in my applet, that would perform the same task, however now with the above onBeforeUnload method, the exit message would appear twice, so had to modify my exit button action performed, so that if the exitbutton was clicked the onbeforeunload method would get passed a null value and not do anything.
    private void exitButton_actionPerformed()
    if (DEBUG) System.out.println("Calling exit");
    doSave();
    window.eval("this.onbeforeunload=null;");
    window.eval("top.close();");
    //continue from here if user cancels the closing of the window
    window.eval("this.onbeforeunload=doSave;");
    window.eval("top.focus()");
    window.eval("document.TestApplet.requestFocus()");
    homePanel.requestFocus();
    }

  • SP L20 hanging whilst user closing network connections on LAN

    I have 2 new laptops on out network Satellite Pro L20. They work ok until the user logs off from he network and the machine hangs on 'closing network connections'. It powers up and down no problem when not connected to the network. I have Win XP SP 2 all the win updates installed, all of the bios upgrades and drivers from the website.
    I need HELP.
    What should I check and do?? it is still the same hanging on closing network connections and I have to hard boot the laptop to restart, although it does restart eventually if I leave it for 10 minutes.

    Hello Sio
    Believe me it is not easy to say why this happen exactly because the LAN configuration of your unit is not known to us. First of all you should discuss it with your network administrator. He is the person who knows how it works in your company.
    I dont know if you have some folders for sharing. It is possible that someone use the data saved on your notebook and in this situation the notebook can not cut off the connectivity. What is with your IP Address (defined one or you get it automatically)?

  • Intercepting JFrame closing

    Ok, so in my GUI adventure, I now need to present a dialog asking if the user wants to save his or her work on closing via the window decoration.
    So, when the user clicks the close decoration on the JFrame, I need to query the use if he or she really wants to leave, if yes, the continue to close the app, if no cancel closing the app. How can I do this?

    set the default close operation like
    jFrame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
    // now handle close operation by urself, by adding WindowListener to jFrame
    For u'r reference I'm adding one sample code use this
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    class CloseFrame extends JFrame
         static boolean canClose = false;
         static CloseFrame jFrame;
         public static void main(String a[])
              jFrame = new CloseFrame("Close Frame");
              jFrame.addWindowListener(new WindowAdapter()
                   public void windowClosing(WindowEvent we)
                        if ( !canClose)
                             return;
                        System.exit(0);
              JButton jBut = new JButton("Allow Close");
              jBut.addActionListener(new ActionListener()
                   public void actionPerformed(ActionEvent ae)
                        canClose = true;
              jFrame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
              jFrame.getContentPane().setLayout(new FlowLayout());
              jFrame.getContentPane().add(jBut);
              jFrame.setSize(500,500);
              jFrame.setVisible(true);
         CloseFrame(String s)
              super(s);
    }

  • Multiple users, closed connections

    Hi,
    I have been building this web application for some time now, and it's going through testing right now. This project has pretty much been a foray into the world of Java/JSP/JDBC/JNDI/etc, considering I've been learning as I go. But - the second the test group actually started using the application, they got random errors. According to the logs, connection closed errors.
    The scenario looks something like this (according to the logs):
    Client A opens a page
    Client B opens a page
    Client B finishes faster and connection closes
    Client A gets SQLException: Connection is closed.
    It's as if there is only one connection (..is there? Truth be told, I'm not exactly sure). I was thinking that it may be a race condition, something to do with threads (although I don't use threads myself, I was just guessing Tomcat might have something to do with this) or something to do with Tomcat's cache, but it's hard to start poking around without knowing what I should poke. I'm betting my money on the all-time favourite - PEBKAC.
    Anyway, the application has a "base" JSP, which in turn loads other classes if necessary.
    The JSP contains:
    /* 8< 8< 8< 8< 8< 8< */
    db=new DBconnection("jdbc/mydb");
    /* 8< 8< 8< 8< 8< 8< */
    db.Close();Configuration file:
    <Resource name="jdbc/mydb" auth="Container" type="javax.sql.DataSource"/>
    <ResourceParams name="jdbc/mydb">
    </ResourceParams>
    /* 8< 8< 8< 8< 8< 8< */
    <parameter>
    <name>driverClassName</name>
    <value>com.mysql.jdbc.Driver</value>
    </parameter>
    <parameter>
    <name>url</name>
    <value>jdbc:mysql://localhost:3306/mydb?autoReconnect=true</value >
    </parameter>The DBconnection class outline:
    public final class DBconnection {
      private Connection con;
      public DBconnection(String resource) {
        this.con=null;
        try {
          Context initContext = new InitialContext();
          Context envContext = (Context)initContext.lookup("java:/comp/env");
          DataSource ds = (DataSource)envContext.lookup(resource);
          this.con = ds.getConnection();                
        catch(SQLException ex) { /* blahblah */ }
        catch(Exception ex) { /* blahblah */ }
        if (this.con==null) { /* blahblah */ }
      /* Update, Query and other methods */
      public void Close() {
        if (this.con!=null) {
          try { this.con.close(); }
          catch(Exception ex) { /* blahblah */ }
    }I tried searching Google and this forum, but I couldn't find anything close to this. I greatly appreciate any advice.

    Hi, thanks for the reply.
    I don't know what the MVC model is, since I am new to JSP and servlets. I do not use servlets as such,
    although I believe that the 'snippets' of java code used within the JSP pages are known as Java servlets?
    Due to the fact that i only use JSP, this would mean that I can't extend servlets from a controller
    servlet. I would be able to implement your idea in Java, but I'm not sure about JSP. Sorry if I am
    missing your point, perhaps I misunderstood. Could I have a controller JSP file which accesses the
    database using abstract methods, and then passes the results back to the other JSP files??
    If you require I can give you more details on my implementation.
    Thanks again for the prompt reply,
    Craig.

  • SetVisible false at closing jInternalFrame

    I would have a button like the closing one, but it mustn't close really the interal frame, only set it not visible

    To get better help sooner, post a [_SSCCE_|http://mindprod.com/jgloss/sscce.html] that clearly demonstrates your problem.
    Use code tags to post codes -- [code]CODE[/code] will display asCODEOr click the CODE button and paste your code between the {code} tags that appear.
    db

  • Closing JInternalFrame with Ctrl+F4 in windows

    Hi,
    I am using JDK 1.4 in Windows NT.I have a JFrame with menus and a desktoppane.In menu's click item i create a JInternalFrame(say jin) if it is not created and add it to desktoppane.If it is already created i just do a jin.setVisible(true) and use moveToFront of desktoppane.I have written a InternalFrameListener in which i make the jin invisible.When i click the close button in jin it hides correctly.When i click the menu it appears again.But when i use Ctrl+F4 key combination(which we use in Windows to close internalframes) it hides,but when i click the menu it dosen't reappear.I have tried to change the defaultcloseoperation to all values but it dosen't work.Is there a problem in my code or ?
    Thanks,
    Ranga.

    Assuming the above is correct:
    public void keyPressed(KeyEvent e){
    if( (e.isControlDown())&&(e.getKeyCode() == 115 ) )doDefaultCloseAction()); rykk

  • Closing JInternalFrame

    I've a problem with the 'X' (top left) of my JInternalFrame.
    I would like to capture the event when I click on the 'X', to execute more methods than a simply close.
    Thanks

    I've try this, with no result, my flag stay at 1...
    frameAssemblage.addInternalFrameListener(
         new InternalFrameAdapter()
    public void InternalFrameClosing (InternalFrameEvent
    t e)
         flagAssemblage = 0;
         );If you copied your code from your app, you put a capital "I" in your method name.

  • Closing JInternalFrame with Ctrl+F4 not using default close action

    If you have a JInternalFrame and set the default close operation to HIDE, when you close the frame with Ctrl+F4, the frame is disposed instead of hidden. Anyone know if this is the way it is suppose to work, or is this a bug?

    Assuming the above is correct:
    public void keyPressed(KeyEvent e){
    if( (e.isControlDown())&&(e.getKeyCode() == 115 ) )doDefaultCloseAction()); rykk

  • Closing JInternalFrame with ESC-Key?

    Hi all.
    Is there a way to close JInternalFrames with the ESC-Key?
    For JDialogs that works good (adding an action to the rootPane's ActionMap) but I cannot figure out how to add this functionality for JInternalFrames as well.
    Any hints?
    Regards
    Carsten

    try this
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class TextButton extends JFrame
    JFormattedTextField tf1;
    Container con;
    public TextButton()
    con=getContentPane();
    con.setLayout(new FlowLayout());
    tf1=new JFormattedTextField();
    tf1.setValue(" ");
    tf1.addKeyListener(new KeyAdapter()
         public void keyPressed(KeyEvent ke)
         if(ke.getKeyCode()==10)     
    System.exit(0);
    con.add(tf1);
    setSize(400,400);
    setVisible(true);
    public static void main(String args[])
    new TextButton();
    }

  • Prompting users for confimation when closing browser window

    Hi All,
    I would like to prompt the user with a popup-screen asking for confirmation that he wants to close the browser when hitting the browser-close ('X') button. Is this possible ?
    If the user chose to cancel the browser window shoud remain open, with all content as it was... and of course if he chooses to continue the window should just close.
    the WDA app is straight forward, and not running inside the portal.
    Thanx in advance
    -Tonni

    Hi Tonni,
    I thought I should add - the portal does implement a work protection mode that does allow you to prompt users if they navigate away from your page - and one of the best ways to implement that is through the FPM and its work protect mode interface.
    However, that still doesn't help, I'm afraid, in the case where you're trying to stop the user closing the browser window...
    I should also point out that some browsers do indeed produce an event which can be trapped on close of the window, and have been hugely exploited by website designers - to the extent that later/better versions no longer support it. Remember the web pages that when you closed spawned 3 more, and those 3 more etc. etc.
    Cheers,
    Chris
    edit:  also worth pointing out that the "Close" button provided within a portal session by the FPM is a form of navigation and can be trapped. Likewise any internal navigation button that perform the same sort of thing within your app.
    Edited by: Chris Paine on Mar 29, 2010 3:08 PM

  • How to track browser closing event?

    Hi Everyone,
    I ran into a problem, which I thought at first would be a very easy thing to solve. Unfortunately, I spent few hours already reading through the forums posts and could not find the answer. Some say it is impossible to implement. I think there has got to be a solution to this problem.
    I need to track user's login time into the JSP application and record both login and logoff timestamps. I had no problem with the login. Just instantiated my TimeTracker object on the index.jsp page and it writes a new row into the database every time user hits this page. However, things are different with the logoff. User can exit out in three dirrent ways. One is to click the "Exit" button, second is when session expires and the third is when "X" button of the browser is clicked and browser shuts down. I can control first two scenarious. I don't know what to do about the user closing the browser.
    I tried capturing onCLose, onUnload or onBeforeUnload events but all of them are also invoked when window gets instantiated or when user clicks on a different page within the application. I also tried instantiating an applet within my JSP template and invalidate session inside its destroy() method but the problem here is that the applet gets destroyed every time a different page within the application is accessed.
    I am ready to give up and just leave it as it is now, let the session expire on its own and take care of the logoff time.
    Did anybody have similar problem and found the resolution?
    Any help would be greatly appreciated.
    Thanks,
    YM

    The common answer is that there is no good way to track the browser closing. A page can't tell the difference between the browser closing and simply navigating to a different page, so determining when the broswer is actually closed is a tough task. There have been some complex solutions in the past, but none seemed to be guaranteed to work, and as such, are pretty much useless for most applications.

Maybe you are looking for

  • Abstract list error in nwds 7.2

    Hi all, I am working with nwds 7.2.  When I am trying to set values to a structure in a bapi using list it gives code error, so I used abstract list.  Please find below the structure and code: structure: Model     UploadProdOrderModel bapi        Zba

  • LAYOUT problems in Pages

    I am new to Pages. I am trying to produce a newsletter and I am having trouble with the layout and column parts. I tried to vary the column width and followed the directions in the pdf manual. But it isn't working for me. I probably need a step by st

  • Problem with a purchase

    How can i buy song from english itunes store if my Apple ID from russian store and that song not available in our store?

  • Always have to type in password

    Since there was an overhaul a few months ago, Apple Discussion Forums no longer allows the passwords to be remembered by Firefox' password manager or by keyword access (whichever does it here for this forum) It used to work that I could just access t

  • When Yosemite wakes from sleep, no password entry box.

    Installed Yosemite v 10.10 on a mid 2011 iMac. I use the standard energy saver settings for sleep and require a password after screen save and sleep. About half the time, when I wake the machine from sleep, the enter password screen appears, but ther