How do I close a JInternalFrame when using subclasses and a separate cla...

The heading should be: How do I close a JInternalFrame when using subclasses and a separate class for the actionListener?
I have just created a JInternalFrame appclication and now I want to structure up my code. I have a Superclass that contains the usual settings for the two JInternalFrame:s, and the two subclasses with frame specific information. Both the JInternalFrames use the same OK button. I want to have the actionListener outside the classes to avoid repetition of code. But the dispose()-function does not work properly, it does not close the opened JInternalFrame. What�s wrong?
class Superclass extends JFrame
     JButton b= new JButton("ok");    
     Superclass()
class Subclass1 extends Superclass
     Subclass1 ()
          add(ok);
       ok.addActionListener(new Listener());
class Subclass2 extends Superclass
     Subclass2 ()
          add(ok);
       ok.addActionListener(new Listener());
class Listener extends Superclass implements ActionListener
     public void actionPerformed(ActionEvent e)
               dispose();
}How do I controll in the Listener class that the button in Subclass1 is beeing pressed?

First of all I think I misunderstood your question. You said you had two internal frames, so I thought you wanted to close the internal frame.
It now looks to me like you want to close the entire JFrame, which makes the code even a little easier. Something like:
JComponent component = (JComponent)event.getSource();
JFrame frame = (JFrame)SwingUtilities.windowForComponent( component );
frame.dispose();
Ok, I will make a try:
public static Container getAncestorOfClass(Class c, Component comp)
w.getAncestorOfClass(w, this); Fiirst you need to learn the basics of reading the API.
"getAncestorOfClass()" is a static method. That means you don't use a variable to invoke the method. You use the class itself.
"w" is a variable, which is a JFrame, but that is not what the first parameter should be. The first parameter is a "Class".
"this" will refer to your Listener class, but you need the Component that generated the ActionEvent.
When I thought you wanted to close an internal frame then the code would have been something like:
JComponent component = (JComponent)event.getSource();
Container container = SwingUtilities.getAncesterOfClass( JInternalFrame.class, component );
JInternalFrame internalFrame = (JInternalFrame)container;
internalFrame.invokeSomeMethodHere();If you need further help then you need to create a "Short, Self Contained, Compilable and Executable, Example Program (SSCCE)", that demonstrates the incorrect behaviour.
http://homepage1.nifty.com/algafield/sscce.html

Similar Messages

  • How do I stop losing drive when using iTunes and Shuffle

    When I plug my shuffle into a USB port I see the device in My Computer nd iTunes opens up. As soon as I try to do something in iTunes, like autofill, the device disappears in My Computer and the autofill brings back an error message that it can't find the device. Help!!!!

    You'll need to install iTunes on your laptop and restore the Phone there.
    There is no way around it.
    itunes.apple.com
    http://support.apple.com/kb/HT1414

  • How can we get ADFSecurity work when used in OC4J, OID and OAM?

    I am getting error in http server log "mod_oc4j: Response status=499 and reason=Oracle SSO, but failed to get mod_osso global context."
    But I am not using Oracle SSO and my client doesn't want to use it either, I am using OAM SSO(CoreIDSSO) in my configuration. Please read the details below.
    I am using ADFSecurity in an app that is protected by OAM. To migrate ADFSecurity permissions from
    system-jazn-data.xml to OID, I used JAZNMigrationTool to populate OID with Grantees and Permissions. OAM gives login page, and authentication works fine.
    But ADFSecurity is not working. ADFComponent Delete button is enabled even for roles that dont have permissions for the iterator delete.
    - The app works fine when I use without OAM. ADF Security permissions work fine.
    - The app works fine when used with OAM, but with ADFSecurity disabled (enforce=false).
    - When I enforce ADFSecurity alongwith OAM, ADFSecurity is not working.
    In the doc "Oracle Containers for J2EE Security Guide b28957", there is a mention of use of CoreIDPrincipal for permissions. Our OID Permissions entries show
    LDAPRealmRole for attribute orcljaznprincipal. I am not sure if this could be the reason.
    We have configured AccessServerSDK for the SOA instance and have policy for the urls in the policy manager. We have entries in orion-application.xml, orion-web.xml and system-jazn-data.xml as per the documentations.
    How can we get ADFSecurity work when used with OID and OAM?

    Have you been able to successfully integrate OAS with OAM & OID? We have similar requriement and so far we have not been able to get it working.
    We have application specific roles which we map to OID roles using orion-application.xml.
    Any pointers to achieve this would be greatly appreciated.
    thanks,
    Dipal

  • How do I manage Lightroom photos when using 2 computers, keeping all edits made on either one?

    Based on http://forums.adobe.com/thread/1308132?tstart=0 I decided to add each question seperately:
    Hello, I'm quite interested in buying Lightroom 5.2. I tried the RC which ran out now. Yet, I have a several questions that I can't really find good conclusive answers to, that I'd like to get answered before buying LR. Please don't write maybe like this or that (assumptions), since I don't want to start my whole workflow and then realize that I have to change everything around, so please answer, if you know for sure that something works and you are, preferably, using that method too.
    This is the biggest question, where I mainly want a conclusive answer:  How do I manage Lightroom photos when using 2 computers, keeping all edits made on either one of them, using the same photos for editing. I won't use DNG. Details: I mainly use my older MacBook Pro, but would like to be able to use my PC as it's way better (Specs: i5 2500K, 16GB RAM, SSD, USB3, nVidia GTX 560 TI etc.). I have 2 external HDs that I could use, one for Backup and one for the actual Photos/Edits. I'll probably need to use it as my internal HDs are quite full, and I can't just delete stuff or move it to an (Developer programs, Lossless music, etc.).
    Based on this, how do I back up the whole thing e.g. Photos folder (all photos and edits, and preferably presets too)?

    I believe it should be possible to work cross-platform without having to relink files each time, or without having to keep exporting/importing the catalog, by keeping the single catalog and the image library on the one external drive which is then switched between systems as needed.
    Obvious first requirement is an external drive that is formatted in such a way (e.g FAT32) that it can be used on both platforms in read/write mode. Given that, if the catalog AND the images parent folder are both established at the same level in one overall parent folder, then it should be possible to take advatage of Lightroom's ability to use relative paths rather than absolute paths to detect the images, no matter if the drive is named (Mac) or lettered (PC). This is how "export as Catalog" works, i.e. it creates a "package", aka a parent folder, containing the catalog and a replica of the exported images folder hierarchy alongside the catalog. Take that "package" to another system (same OS or not) and "it just works" even if the drive letter is different or the OS is different....because the relative path from catalog to images is still the same.
    I haven't tested this cross-platform (though I have between different PC systems with different drive letters) so for me it's still just a theory, but there may be others who have done this successfully.

  • How do I close an app when it is playing  ie. a Podcast

    How do I close an app when it is playing  ie a podcast?

    I really do not understand what you mean. You can pause the Podcast and then go to another app. you can also go to the other app and then double click the Home button. Then touch and hold the podcast app/Music app and tap the circled minus sign to stop the podcast. You can also just double click the Home button and go to the music controls and tap pause.

  • How do I stop system sounds when using AirPlay on my MacBook Pro?

    Hi all,
    Probably a quick question, but I'm fairly new to Macs. I've a Macbook Pro 13 Late 2011 and now I've got an Apple TV, I use AirPlay. But how do I stop system sounds when using AirPlay?
    Many thanks in advance, Jon.

    Open AirPort Utility located in HD > Applications > Utilities
    From the AirPort Utility menu bar click AirPort Utility > Preferences
    Deselect:   Monitor AirPort base stations for problems

  • Can you explain when using keywords and addding them to various clips pressing ctrl and a number eg. 1 or 2 it simply closes down FCPX.  Just to the dock as would th yellow -sign. As you gather I am new to this program having only used Final Cut Express 4

    Can you explain when using keywords and addding them to various clips pressing ctrl and a number eg. 1 or 2 it simply closes down FCPX.  Just to the dock as would the yellow -sign.  I am new to this program having only used Final Cut Express 4 previously.
    iMac (early 2009) 24in 2.93GHz 4GB 1066MHz DDR3 SDRAM (To be upgraded ot 8GB in the nextfew days) os x 10.7.2 Lion
    Re: Why don't my arrows on the time line operate and allow me to move to the start and end of the timeline. Iam using the trial version 

    Check System Preferences. I think Control-1 is used by something in the OS now. Switch it off. It's a major p[ain the way the OS is taking over more and more of the keyboard, allowing less options for application use.

  • What is Dashboard Client and how do I close it?  I use OSX Mavericks on my iMac.

    What is Dashboard Client and how do I close it?  I use OSX Mavericks on my iMac.

    Hi there kburgee! Other can be anything from App Data (information saved from apps like game progress, or passwords) to or old messages that you haven't deleted! The absolute best way to clean up some space is to restore your iPhone.

  • I'm having a problem with the application Dropbox and I want to uninstall it. In finder it does not allow me to move it to trash telling me the dopbox application is open. How do I close it? when it shows up nowhere as an open application?

    I'm having a problem with the application Dropbox and I want to uninstall it. In finder it does not allow me to move it to trash telling me the dopbox application is open. How do I close it? when it shows up nowhere as an open application?

    Is there a DropBox icon up in the menubar you can click on & see quit DropBox?
    https://www.dropbox.com/help/41

  • How do u close the apps when done with them to save power with iOS 7

    How do u close the apps when done with them to save power with iOS 7

    To close out apps, simply double click the home button and instead of holding down the app icons and clicking on the X mark in older versions, you have to swipe the app window up and away.
    Also you can save on battery by turning of background app refresh from settings .... See this article for details , http://nyacomputing.com/how-to-close-out-background-apps-in-ios-7-and-save-on-ba ttery/

  • How can I customize the toolbar when using the attribute browser

    In CVI 2012, the toolbar changes depending on the environment, e.g. it is different for the source window and the UI editor. The toolbar can be customized using the menu Options / Toolbar...
    Unfortunately, when using the attribute browser of the UI editor, another toolbar is displayed, i.e. not the UI editor toolbar.... I would have assumed that the attribute browser belongs to the UI editor, obviously it doesn't... So how can I customize the toolbar when using the attribute browser?
    Solved!
    Go to Solution.

    Luis,
    It's nice to have you back 
    Thank you for the clarification, so I'll elaborate a bit more: In the regular workspace toolbar, I have a disk symbol to save the file. This symbol is gone in the attribute browser...
    So I have three different toolbars, for source code (workspace), UI editor, and the UI editor displayed but the attribute browser clicked on (selected)... 
    Thanks
    Wolfgang
    Source code:
    UI editor:
    Attribute browser:

  • My photos are sharp but become soft when used in and IDVD slide show.

    My photos are sharp but become soft when used in and IDVD slide show. How can I prevent this from happining??

    Hi,
    I suggest that you try unchecking both of the crop options - landscape & portrait.
    To re-create your situation, I had to check the crop for landscape pictures option.
    I prefer to have control over any cropping so I tend to crop each image first before creating the slide show.
    Brian

  • Building executables when using LV and MATRIXx

    Hi!
    With respect to Building executables when using LV and MATRIXx, I need clarification on following:
    1) Pre-requisites to use MATRIXx? We have LV 7.1 FDS with application builder.
    2) Licensing scheme? We would like to have MATRIX on 3 development stations.
    3) Can we build stand alone executables when using MATRIXx with LV?
    4) Do we need to purchase any addon to achieve (3) ?
    Thanks,
    Gurdas
    Gurdas Singh
    PhD. Candidate | Civil Engineering | NCSU.edu

    Hello Gurdas,
    Before I answer your questions, I am curious to know what you have in mind for the stand alone executables you are interested in building. It may help me to know a little more detail about your plans. Depending on your application, some of these answers may or may not be applicable. In any case, here are answers to your questions:
    1) There are no prerequisites for using MATRIXx. LabVIEW is not required. However, with LabVIEW FDS, you do have an Xmath Script node located in the Functions > All Functions > Analyze > Mathematics > Formula palette. This node can be used to call Xmath scripts from LabVIEW.
    Note: To use the Xmath Script node successfully, you will want to install LabVIEW 7.1.1 Maintenance Release. Refer to KnowledgeBase 300A6NDT: How Can I Resolve MATLAB and Xmath Script Node Issues in LabVIEW?
    2) There are two licensing options for MATRIXx: node-locked and floating (concurrent). A node-locked license is restricted to a specific node and can be installed and used on that single computer. A floating (concurrent) license allows use of the product by a specified number of concurrent users on any computer on a local area network that includes a server running a single license manager. For more information, follow the link to the MATRIXx Price List from Products and Services: MATRIXx.
    3) There are two ways you might build executables when using MATRIXx and LabVIEW. One way uses a component of MATRIXx to automatically generate C code. AutoCode is a component of MATRIXx that allows the user to turn system models into C code. This C code can then be compiled into an EXE or DLL. If built into a DLL, LabVIEW can be used to call the DLL. A more thorough explanation of this is provided in Developer Zone Tutorial: Running MATRIXx SystemBuild Models in LabVIEW/LabVIEW Real-Time.
    Another way that may work is to build an executable from a LabVIEW VI that uses an Xmath Script Node. Any target machine running this executable would need to have Xmath and the LabVIEW Run-Time Engine installed.
    4) No other add-ons are needed for (3). Do be sure to refer to the note following the answer to (1).
    Regards,
    Eric M.

  • Lion crashes when using Firefox and Safari, have found a fix for this.  I can't believe they would just let us hang.  Very frustrated.

    How do I fix frequent crashes when using Firefox or Safari???  I see a lot of people have this problem...is there a solution yet?

    Try posting in Safari forum, you'll get better help there.
    https://discussions.apple.com/community/mac_os/safari

  • [svn:fx-4.x] 15119: Menu. popUpMenu textAlign should be start rather than left so it works correctly when using FTEText and direction =rtl.

    Revision: 15119
    Revision: 15119
    Author:   [email protected]
    Date:     2010-03-29 13:49:52 -0700 (Mon, 29 Mar 2010)
    Log Message:
    Menu.popUpMenu textAlign should be start rather than left so it works correctly when using FTEText and direction=rtl.  Also made same change for AccordionHeader, CheckBox and RadioButton just to be safe.
    QE notes:
    Doc notes: None
    Bugs: SDK-26028
    Reviewed By: Kevin
    Tests run: checkintests
    Is noteworthy for integration: No
    Ticket Links:
        http://bugs.adobe.com/jira/browse/SDK-26028
    Modified Paths:
        flex/sdk/branches/4.x/frameworks/projects/framework/defaults.css

    Thank you so much wchp, this is brilliant. I have had this annoying problem for a long time. I eventually rang Mac support, they did not know how to fix the problem as you have suggested so they instigated many hardware replacements which eventually left my iMac severely crippled. They eventually replaced it with the latest model. But I spent two months working with a disabled computer which really interfere with my work.
    Your solution appears to have solved my problem, at least so far, but I am hopeful that it is a permanent fix. I hope that your suggestions are taken up by Apple support. This may solve many users problems and avoid Apple making expensive fixes that don't actually work.
    I thought that the new iMac would not have the 'Wake up from sleep by painting in the login window' problem but it did, this really annoyed me. Anyway now the problem appears to be solved, it's not I will repost and keep working on it. Thanks again.

Maybe you are looking for

  • Resetting a view w/struts

    Hello This is a problem I am having w/ struts. I have a page, results_list1.jsp that has an href that calls, add1.jsp. Add1.jsp is the view for the data fields of the object. Add1.jsp has a submit that calls Add1Action. I have an Add1Form w/ Reset me

  • How to capture system status & date in project?

    Hi all I'm using transaction CJ20N for managing all R & D projects. I want to make a report where I need to capture status REL & CNF of every stage with respective dates. Can you help me to provide a procedure how to find it through tables? For examp

  • XML out ... and in

    For an automated data transfer I need to get a database (relational structure) to export to XML and to be able to import a similar structure sent by our partners. I have been googling on this and there seems to be a massive number of options and tool

  • Ipod touch keeps dropping wifi in dorm room

    I recently moved into a college dorm and i am having trouble with my ipod touch. Everytime i connect to the wifi from my roomates router it drops it after a few minutes. I know that is is not the ipod because it works fine with other wifi networks an

  • Always prints 2 pages

    yet another challange. Everytime I print in pages it will spit out a second blank page. It says "page 1 of 1" but it always, when done with the print, kick out another sheet of blank paper. weird