Closing a JFrame when you click on another JFrame...

Hi,
I was hoping someone could help me.
I have a main application, which assigned to one of my buttons is a new instance of another class which loads up another GUI. What i wish to do is when the user pushes this button and loads up the new GUI, i want this new GUI to close automatically when the user clicks back on to the main application GUI.
Is this possible???? I have tried searching for a solution, however I have hod no luck :(
If anyone has any suggestions please let me know, thank you!
Claire
x

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Test2 extends JFrame {
  public Test2() {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container content = getContentPane();
    JButton jb = new JButton("New Frame");
    content.add(jb, BorderLayout.SOUTH);
    jb.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent ae) { showFrame(); }
    setSize(300,300);
    setVisible(true);
  private void showFrame() {
    JFrame jf = new JFrame("I am new frame");
    jf.setBounds(300,300,200,200);
    jf.getContentPane().add(new JButton("I am button"));
    jf.setVisible(true);
    jf.addWindowListener(new WindowAdapter() {
      public void windowDeactivated(WindowEvent we) { ((JFrame)we.getSource()).setVisible(false); }
  public static void main(String[] args) { new Test2(); }
}

Similar Messages

  • DW CS6 - Spry collapsible panels - How to have panel close when you click away from it?

    I know typically onmouseout is used to close other items, but I could not figure it out with the spry collapsible panel. I have the panel opening onclick and closing onclick, but I would really like for it to close when you click anything else on the page outside of the panel.
    Thank you!

    Sorry, I did not mean other collapsing panels close when you click away from it. I simply meant in general for the closing after clicking away function, you can use onmouseout. I was working on something with collapsing panels and I wanted it to show the information when you clicked on it, but when you click on another panel, they both remain open. I really want both to close. I believe accordion does this, but not quite what I am looking for either.
    Here is a better example of what I would prefer: Houston Public Library
    If you visit their page and click "Find it" a box pops down with information and then when you click anywhere else on the screen, it closes that box. When you click "Research," it closes the "Find It" box and opens the "Research" box. There is likely a much better way to do this, but I am pretty new to this.
    Any assistance is very much appreciated.
    Thank you!

  • Could someone help me restore my photos?  I was trying to "restore my database" in iPhoto when it shut down - now my thumbnails are distorted, logged under a new name, and when you click on a thumbnail it opens as another photo.  I was following another "

    Could someone help me restore my photos?  I was trying to "restore my database" in iPhoto when it shut down - now my thumbnails are distorted, logged under a new name, and when you click on a thumbnail it opens as another photo.  I was following another "helpful hint" hold down the option and command key and restart iPhoto - select the top three and you should be able to get rid of the dreaded exclamation point.  My MAC ran through the first two options dealing with thumbnails, but crashed during the "restore database"  step and now I have a mess.  Help, please.  Thank you.

    Download iPhoto Library Manager and use its rebuild function. This will create a new library based on data in the albumdata.xml file. Not everything will be brought over - no slideshows, books or calendars, for instance - but it should get all your albums and keywords back.
    Because this process creates an entirely new library and leaves your old one untouched, it is non-destructive, and if you're not happy with the results you can simply return to your old one.  

  • Was trying to restore my database in iPhoto when it shut down - now my thumbnails are distored, logged under a new name and when you click on a thumbnail it opens as another photo.  Help, please

    Could someone help me restore my photos?  I was trying to "restore my database" in iPhoto when it shut down - now my thumbnails are distorted, logged under a new name, and when you click on a thumbnail it opens as another photo.  I was following another "helpful hint" hold down the option and command key and restart iPhoto - select the top three and you should be able to get rid of the dreaded exclamation point.  My MAC ran through the first two options dealing with thumbnails, but crashed during the "restore database"  step and now I have a mess.  Help, please.  Thank you.

    Repost in the iPhoto forum, where the real iPhoto wizards live:
    https://discussions.apple.com/community/ilife/iphoto

  • When two or more tabs are opened after this when I click on another tab which is opened then firfox stopped responding and open automatically all the tabs in diffreent windows

    <blockquote>Locking duplicate thread.<br>
    Please continue here: [[/questions/873886]]</blockquote>
    when two or more tabs are opened after this when I click on another tab which is opened then firefox stopped responding and open automatically all the tabs in different windows

    If it works in a new window then you can drags tabs from the not working window to that new window.
    You can also try to close the tabs via Ctrl+W and restore the closed tabs via Shift+Ctrl+T

  • I have an app in my app store that is requiring an update but I never purchased the app and when I click update, another apple ID pops up that is not mine.  Now i keep getting reminders to update the app and I cant get rid of it from the app store.  Help.

    I have an app in my app store that is requiring an update but I never purchased the app and when I click update, another apple ID pops up that is not mine.  Now i keep getting reminders to update the app and I cant get rid of it from the app store.  Help.

    You installed a hacked app, originally from the Mac App Store. It contains the receipt for a different app, downloaded using an account that you don't control. You need to identify and remove the hacked app.
    Important: The app you need to remove is not necessarily the one named in the App Store notice. For example, if the App Store says you need to update "Twitter," the hacked app may be "Angry Birds" or something else entirely. Don't make any assumptions about which app you're looking for. To find it, you have to carry out a systematic search.
    Triple-click anywhere in the line of text below on this page to select it:
    kMDItemAppStoreHasReceipt=1
    Copy the selected text to the Clipboard (command-C).
    In the Finder, press the key combination command-F to open a search window, or select
    File ▹ Find
    from the menu bar. In the search window, select
    Search: This Mac
    from the row of tokens below the toolbar. Below that is a popup menu initially showing Kind. From that menu, select  Other...
    A sheet will drop down. In that sheet, select Raw Query and click OK or press return.
    Now there will be a text box to the right of popup menu. Click in that box and paste (command-V).
    The search window will show all the App Store products you've installed. Compare those search results with the list of your purchases from the App Store. To see the complete list, you may need to unhide hidden purchases. If any apps were download from the App Store using other Apple ID accounts that you control, sign in to the store under each of those ID's and check the purchases.
    At least one of the items listed in the search window is not among your purchases in the App Store. Move each such item to the Trash. You may be prompted for your administrator password. Empty the Trash.
    Log out and log back in. Test.

  • Why doesn't Skype not close when you click the X b...

    I'd like to get some input as to why Skype does not close when you click the red X button on the top right corner but rather only gets minimized. It's frustrating and makes no sense at all. The only way to close Skype is to right click the icon in the tray and choose "Quit Skype."
    I'd like to understand why this useless feature exists. It renders the minimize button ( - ) useless, which is only two squares away from the X button. 
    Please don't proceed to list other programs that do this (i.e. some antivirus software) as that was not what I asked. It's standard for programs to close when the X button is clicked, as will happen momentarily when I click the X button on my Chrome browser window when I'm done typing this quation. Thanks

    What he was talking about was setting it to ""run as administrator" in the shortcut/executable as you should know that would run the application in a true administrator mode (like Windows XP) vs. the default crippled administrators group in Windows.  I personally have not had to do this since I have not run into the issue but for those that have, people claimed it has helped/resolved the issue.  In regards to following UI interaction rules, it does as it actually closes the form.    Skype doesn't send an additional closure to the resident system tray icon form because it's a memory resident communication program.  Some programs give you that option, others don't.   Geforce Experience is one of the latest programs I use, that doesn't.  Nobody forces anything on you.  If you feel your family is "forcing" something on you, you always have the option of "forcing" something on them or suggesting another method you prefer  in order to stay in contact with you.  In the end that's a family issue, not a Skype one.
    If you want to close Skype down in one click you can do so using the provided shortcuts in the following thread.  You can also assign those shortcuts hotkeys or assign them to a key on your keypboard/mouse using additional key mapping software to completely close Skype with the press of a single button.
    http://community.skype.com/t5/Windows-desktop-client/How-to-quit-Skype-with-keyboard-shortcut-on-Win...

  • How do you delete songs that you purchased through iTunes but don't show up when you connect the iphone to iTunes they don't show up in music when you click on "On this phone"? I have my phone setup to manually manage music. Please help.

    How do you delete songs that you purchased through iTunes but don't show up when you connect the iphone to iTunes? They don't show up in the music section when you click on "On this phone". Side Note: I have my phone setup to manually manage music. Please help.

    Hi, Mrs.Frankie57. 
    Thank you for visiting Apple Support Communities.
    If you want to delete a song from your iOS device on iOS 7, tap Songs, swipe the song from right to left, then tap Delete. The song is deleted from iPhone, but not from your iTunes library on your Mac or PC, or from iCloud.
    iPhone User Guide
    Cheers,
    Jason H.

  • I'm on a website that usually when you click on the open chat(popup) link it opens a certain now, but now they are opening maximized all the time. How do I get them to open the proper size?

    It was opening the proper size and now it doesn't

    Works normally for me. The script that runs when you click the link will check to see if it already opened a window and try to switch to it, but if you are starting from scratch, this shouldn't be an issue.
    There probably are quite a few add-ons that affect popup window behavior. To see whether an add-on could be responsible, you could test the page in Firefox's Safe Mode.
    First, I recommend backing up your Firefox settings in case something goes wrong. See [https://support.mozilla.com/en-US/kb/Backing+up+your+information Backing up your information]. (You can copy your entire Firefox profile folder somewhere outside of the Mozilla folder.)
    Next, close Firefox, hold the Shift key, then restart Firefox. You will get a [https://support.mozilla.com/kb/Safe+Mode Safe Mode dialog]. Just click "Continue in Safe Mode" and do not "reset" anything just yet.
    If the window displays at the specified size in Safe Mode, one of your other add-ons (especially in the Extensions category) may be overriding it.

  • My iMac locks up constantly in email. I click on one or two emails. Then when I click on another email, I get the spinning wheel and have to relaunch. Why does it get confused and lock up?

    My iMac locks up constantly in email. I click on one or two emails. Then when I click on another email, I get the spinning wheel and have to relaunch. Why does it get confused and lock up? Seems like it is stuck.

    10.6.8 here, MacBook Pro. Comcast. Mail  freeze ups. Occasional warnings to use "Log Out" under the Apple icon.
    Disk Repair run several times. Shows lots of Java  "remote" issues.
    I run Disk Repair several times, shows a lot of Java, "remote" issues.
    Restart don't know if it helps, I do it all the time. What's with quitting Mail but it doesn't quit, and why a separate maneuver to "Log Out".
    i

  • Since i upgraded to FF4 Beta. The suggestion bit in my Google toolbar, works but not when you click on a suggestion?

    It gives suggestions but when you click on them nothing happens they just disappear.

    Hi satorilori-
    You might try this:
    -> Clear Cookies & Cache
    https://support.mozilla.com/en-US/kb/Template:clearCookiesCache
    -> Clear the Network Cache
    -> Reload web page(s) and bypass the cache.
    Press and hold Shift and left-click the Reload button.
    Press "Ctrl + F5" or press "Ctrl + Shift + R" (Windows,Linux)
    Press "Cmd + Shift + R" (MAC)
    Check and tell if its working. Hope that helps!

  • Please help. My facebook app will not open on my iphone 4. I deleted it,numerous times and downloaded it again. It uploads, but when you click on the icon, it flickers then closes.  Help.

    Please help. My facebook app will not open on my iphone 4. I deleted it,numerous times and downloaded it again. It uploads, but when you click on the icon, it flickers then closes.
    Help.

    Then the next step would be to restore your phone.  My advice is that prior to restoring you import your photos and videos to your computer and back up your contacts (by syncing them with iCloud or to a supported program on your computer using iTunes) as a number of users report losing these when restoring their device.

  • Why can't I get the image to view larger when you click on a thumbnail?

    I thought that there was a way to have the image open up larger in a new little window when you click the thumbnail on a photos page....when I click a thumbnail on my photos page it takes me right to slideshow view and the images are displayed too small to see fine detail (I am a retoucher, so my clients need to be able to see hi res images) I can't find a way to change the size of the slideshow images or to get my thumbnails to click open to a hi res version in a new window. The only solution I can think of is to use a blank template page, make each small image a link to a hidden page with the image at hi resolution....but this would take forever and I would have a gazillion pages on my site that way. Any idea how to get around this. Seems like the older version of iweb didn't have this problem...????
    (for an example of what I mean, my site: http://www.katesilsby.com (retouch page) and what old iweb did and what I want to happen: http://web.mac.com/vogier/iWeb/vivian%20ogier/wardrobe.html

    (for an example of what I mean, my site: http://www.katesilsby.com (retouch page) and what old iweb did and what I want to happen: http://web.mac.com/vogier/iWeb/vivian%20ogier/wardrobe.html
    iWeb2 photos page is completely different from that of iWeb1.
    iWeb2 photos page can be retro back to iWeb1, but not without major javascript coding.
    or using completely different previewing method for larger image, example: http://hdl.50webs.com/Lytebox/Photos.html

  • How can I have a PDF in Full Screnn Mode without it goinging to the next page when you click?

    I'm trying to make, let's say, a mini website using a pdf that includes hyperlinks. I also want the PDF to open in FULL SCREEN Mode. For some reason, when in FULL SCREEN mode you can click on the links (works excellent), but when you click on an area of the page that is NOT a link, it forwards you to the next page in the PDF.
    I ordered the full version of Acrobat X Pro, and thought that it would work saving it out of Powerpoint (original file), but I had to disable the add-in because it just kept on crashing.
    I can't seem to find where i can control the "Do Not Forward to Next Page OnClick".
    Help!
    Thanks!

    If you just purchased Acrobat 10, you might be eligible for a free upgrade to Acrobat 11, which is suppposed to have much improved export to PPT.

  • Hi there, Can you please HELP ME? I created a signature for my email account, but I can not choose it because the option is daded under "none"and nothing happens when you click on it! Thank you, Johan

    Hi there, Can you please HELP ME? I created a signature for my email account, but I can not choose it because the option is daded under "none"and nothing happens when you click on it! Thank you, Johan

    This can be a problem with the file places.sqlite that stores the bookmarks and the history.
    * http://kb.mozillazine.org/Bookmarks_history_and_toolbar_buttons_not_working_-_Firefox

Maybe you are looking for

  • Is there a way to create a second Toolbar in Safari 5

    With the introduction of Extensions in Safari 5, I am having too many buttons on the Toolbar. I am thinking will that be possible to introduce a second toolbars - which behaves exactly the same as the default Toolbar that you can use the Customize To

  • SQL Loader bug

    2 day ago I meet with problem to load text file to Oracle DB with SQL statment in control file. It's my control file: LOAD DATA INFILE '/tmp/123/22-12.txt' REPLACE INTO TABLE VL_LOG (date_time SYSDATE, SOURCE POSITION(02:16) "TRUNC(SUBSTR(:SOURCE,1,3

  • I downloaded Lion to my iMac and now can not get on the internet

    I cant figure what i have done wrong  my other computers are working fine.

  • Get an amber flashing light wherever I connect

    I just purchased an airport express, my home set up is a bt 2wire router...thing(?) which goes into a d-link switch this then goes out to the other computers in the house via ethernet cables, although the 2wire151 is wireless the room I want to use m

  • Help with maverick update.

    I have the late 08 MacBook and I want to install maverick on there but I am unable to install it becaus of SMART errors. Can I just format my harddrive then install it via USB?