How do I find the parent JFrame of a JMenuItem?

When an ActionEvent occurs from a JMenuItem selection, how can
I get a reference to the JFrame the JMenuItem is on?
Thanks

Good afternoon...
it's a pretty good / standard idea to make your event-thread a subclass of the JFrame. i.e.:
public class MySwingApp extends JFrame implements ActionListener {
    public MySwingApp() [
        super("My App Title");
        // ...build your GUI...
        // ...register this as your action listener for the menu items...
    /* this is in the class that is the JFrame of the application */
    public void actionPerformed(ActionEvent ae) {
        System.out.println(ae.getCommand());
}hope that helps
Schultz

Similar Messages

  • How do i find the visible area...

    Hi everyone.
    I'm trying to get the size of the visible area of a JFrame, but it keeps returning 0. I use this.contantpane().getsize() . Its because I need a drawing area which occupies a certain area of the contentpane. How can I find the visible area without the toolbar and border around the frame?
    Here is my code:
    public class CgraphForm extends JFrame implements Runnable {
        private int h = 600; // Height of JFrame
        private int w = 800; // Width of JFrame
        private double pad; // Padding edges size [%]
        private JButton btClose = new JButton();
        private CGUI gui;
        private boolean running = true;
        public CgraphForm(CGUI _gui) {
            // Name of frame send to parent (super) which is the JFrame
            super("Temperature");
            gui = _gui; // Used to enable the applet again
            pad = 0.05 * h;
            System.out.println("GraphForm thread started");
           try {
               jbInit();
           } catch (Exception ex) {
               ex.printStackTrace();
        public void run() {
            // Interrupt makes the thread terminate proberly by ending its run method
            while (running) {
                try {
                    Thread.currentThread().sleep(100);
                } catch (InterruptedException ex) {
                    running = false;
        private void jbInit() throws Exception {
            setDefaultCloseOperation(DISPOSE_ON_CLOSE); // Disposes the JFrame when its closed
            this.setSize(w,h);
            this.setLocationRelativeTo(null); // Location af JFrame on screen
            this.addWindowListener(new CgraphForm_this_windowAdapter(this));
            Container contentPane = this.getContentPane();
            Dimension size = contentPane.getSize();
            System.out.println(size);
            contentPane.setLayout(new XYLayout());
            // PENDING graphSize mangler et offset paa bredden, sandsynligvis kanten af framen
            Dimension graphSize = new Dimension( (int) (w - 2 * pad),
                                                 (int) (h - 0.45 * h));
            JPanel panel = new JPanel;
            contentPane.add(panel, new XYConstraints((int)pad,(int)pad,(int)graphSize.getWidth(),(int)graphSize.getHeight()));
            this.setVisible(true);
            btClose.setText("Close window");
            btClose.addActionListener(new CgraphForm_btClose_actionAdapter(this));
            contentPane.add(btClose, new XYConstraints((int)pad, 500, -1, -1));
    }/lars

    I need the size to draw my panel.
    You shouldn't do. Your panel should be able to draw itself without knowing its size. Assuming your panel is just a plain space which you draw on, that means one of two things: either you make its rendering logic sensitive to its own size (which you can detect in the paint() method) or you can assign it a preferred size and then place it in a JScrollPane to ensure that it can always be viewed. Both of these are fairly straightforward solutions.

  • How can i find the size of a computer screen?

    I want to be able to size a JFrame to whatever the monitor's screen size is. How can you find the dimensions of the screen?
    Thanks
    Mike

    http://www.java-tips.org/java-se-tips/java.awt/getting-the-screen-size.html

  • I have bought a film from itunes and the credit has come out of my account, but i can't find the film anywhere, it said it was downloading, then i left the laptop and on return i couldn't find the film. how do i find the film?

    i have bought a film from itunes and the credit has come out of my account, but i can't find the film anywhere, it said it was downloading, then i left the laptop and on return i couldn't find the film. how do i find the film?

    Maybe it is in the Purchased category of iTunes,
    Try going there

  • How do I find the cookies I want to keep

    Recently I asked for some help but I think my request has got lost.
    I had beenadvised to save the cookies I want to keep but this is beyond me.
    My question is how do I find the cookie I want to keep? It is a cookie for an ebook and I have no idea what it is.
    Will deleting all other cookies mean that it will also delete my passwords and log ins on several sites? I don't want this to happen.
    Which brings me to the last point - You say that if I list exceptions to cookies I want to keep (at least I think that is what you mean), how do I find all those cookies?
    Again, sorry for troubling you but until I can find out more about the cookies, I don't want to delete these in case I delete the wrong ones, such as the ebook.
    Thank you cor-el. I do appreciate your advice...enormously.
    Anthony

    Dear Sir,
    Thank you so much for the above. It will be of great help in telling me where to go. But my problem is that if I can find cookies, I don't know which ones I want to keep. Are they labelled with the sites they refer to? If so that will help me. Apart from one which is the cookie I need to get to my online ebook, I guess there are cookies for the various passwords I have saved?
    Forgive me but I am an old man and not real great with computers.
    Thanks,
    Anthony

  • In Mountain Lion, how do I find the location of an open Preview File?  The file "properties" tab is no longer available.

    I typically have several open Preview files at any one time and often forget where, sometimes if, I saved them.  In Mountain Lion, how do I find the location of an open Preview File?  Tried holding option + command in spotlight but I don't see a path name appear anywhere. 

    Yes, cmd-option on a file you choose in Spotlight and the path will appear at the bottom of the Preview window.
    EDIT: Also, if it is bookmarked the path is in Bookmarks.

  • How can we find the most usage and lowest usage of table in Sql Server by T-SQL

    how can we find the most usage and lowest usage of table in Sql Server by T-SQL
    The table has time stamp column
    StartedOn datetime
    EndedOn datetime

    The Below query has been used , but the textdata column doesnot include the name of the table ServiceLog.
    SELECT
    FROM
    databasename,
    duration
    fn_trace_gettable('F:\Program
    Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\Log\log_148.trc',
    default)
    WHERE
    DATABASENAME='ZTCFUTURE'
    AND TEXTDATA
    IS
    NOT
    NULL
    --AND TEXTDATA LIKE 'SERVICE%'
    order
    by cpu
    desc; 

  • How do I find the wifi passord on my iphone?

    I sometimes need to get a wifi password at a location i have saved before. my iphone hooks up fine but how do i find the password?

    The Time Capsule automatically scans to find the best available channel to use when it is powered up.
    You can see the channel that the Time Capsule is using by holding down the option key on your Mac while you click on the WiFi icon at the top of the screen.
    On the example below, the Time Capsule is using Channel 149 at the present time.

  • I am trying to download xfinity tv go app. I can not find it in my App Store and can not download it from the comcast website. All I get is a blank screen in the App Store. My Apple ID is associated with a Canadian address. How can I find the app?

    I am trying to download xfinity tv go app. I can not find it in my App Store and can not download it from the comcast website. All I get is a blank screen in the App Store. My Apple ID is associated with a Canadian address. How can I find the app?

    Its possible the App is not available in the Canadian store if the link doesn't work for you.
    https://itunes.apple.com/us/app/xfinity-connect/id320788270?mt=8

  • How can I find the URL for an iCal calendar in iCloud so I can make a link to it on a web page.

    I have a single iCal calendar that I want people to access through my webpage.  How can I find the URL so that they can view the calendar without having to subscribe to it.  I converted to iCloud from .Mac and I can see that changes to this calendar are not showing up.

    Mmmh.. i see... I don't know wether it is possible for people just check calendars without subscribing to them... I have been sharing some calendars in my website (maybe you can have a look at it in order to check wether it could be a possible solution for you)
      http://web.me.com/andreabruschi/englishplanet/English_Courses.html
    Cheers
    Andrea

  • How can I find the location of an app on my iPad 2?

    How can I find the location of an app on my iPad 2? The app comes up with a search, but that seems to be the only way to find it. I just installed the app today, but I can't figure out where it is. It has a pretty distinctive icon, and I've looked through all of my apps and even in folders (even though I don't know how it would have gotten there). I want to put it in an appropriate folder under the right subject, but I can't find it to do this. I can use the app, since I can find it through a search though. I have a lot of apps, but I looked very carefully and can't find it. Is there a way to ask my iPad to locate it for me? It's a $25 app and one I plan to use regularly, so I want it located in the folder of my choice.This problem makes we wonder if I have other "missing" apps, apps that I could  find if I happened to think to search for them, but that don't appear to be on my iPad (even though they actually  are).

    You were right about the homescreens. I had turned my iPad off for the night with less than three full homescreens of loose apps, those not in folders. When I turned the iPad on this morning to try your suggestions, I had five full pages of loose apps. They just appeared when I restarted, and there was the app I was looking for, easy to find. Last night I was deleting apps I decided I wouldn't use, organizing useful apps into folders, and making sure I had as few pages as needed by making sure the gaps made by the moved/deleted apps were closed. The missing apps didn't show up at that point; I was just left with fewer than 11 pages. The apps only showed up when I restarted this morning. There were almost three extra pages of apps that weren't there last night. I know there must be other things missing, since all of the pages are full. So I tried your suggestion in iTunes. I connected my iPad, found an app in the alphabetical list on the left, and double clicked it. This brought me to the app's homescreen (and its home folder when applicable), the place where it was located. In order to identify which page that was, I had to scroll through the screen shots of the homescreens that was below the homescreen that was showing until I found the homescreen whose number was in white. Then I could count the pages on my iPad until I got to that page. I'll have to delete more apps and organize more into folders to see what else might show up. There are just too many apps available for special education, and I'm in the process of figuring out which are the best for my needs. Thanks so much!

  • Hello! I have one iTunes library on my iPod and one iTunes library on my computer. When I connect my iPod touch to my PC, however, I cannot find any files in my iPod except for pictures. How can I find the music files so I can add them to my iTunes?

    Hello! I have one iTunes library on my iPod and one iTunes library on my computer. When I connect my iPod touch to my PC, however, I cannot find any files in my iPod except for pictures. How can I find the music files so I can add them to my iTunes?

    You can't do that.
    And before you decide to store any music that you own on a computer at work, talk to your IT department. Many organizations do not permit it for legal reasons. Standard policies are that anything stored on company owned computers is the property of the company. It could not be legally stored on their machines unless you transfer the licenses and all copies, physical and digital, to the company, meaning you no longer own the music. If they were to be audited and could not prove that they own the music, they would be subject to copyright violation penalties. Just use your iPod when you're at the office if you want to listen to music.

  • How can I find the serial number for my creative suite CS6 I bought it from a store.

    How can I find the serial number for my creative suite CS6 I bought it from a store.

    https://www.adobe.com/account.html for serial numbers or subscriptions on your Adobe page... or
    Lost serial # http://helpx.adobe.com/x-productkb/global/find-serial-number.html

  • How do I find the FTP info for my site?

    I created a site with Wix.com. Since then I've been exploring Dreamweaver, and the author of "Dreamweaver for Dummies" suggets that the best way to make changes to my existing site is to use Dreamweaver's FTP capabailities to download the existing pages. But Wix doesn't support FTP -- so they tell me, and simpleurl.com (where I regeistered my domain name) and which is somehow involved in the posting of my site) can't help either. Here's the Dreamweaver page that I need to fill in.
    How do I get this information?

    Yup, it's basically free, altho you can upgrade a little, as I've done. 
    And I took
    a careful look at the "source" for the pages I've created. That code will 
    show
    nothing of what I've written -- text-wise. It's all stored on the Wix 
    servers
    and accessed with various scripts. You can re-locate your Wix-created site
    after 60 days -- not before. So the suggestion I got from the "...Dummies"
    book doesn't apply here.
    Nonetheless, I'm going to continue to learn how to use Dreamweaver. Maybe
    after my 60 days are up I'll wanna move it. Don't know.
    MurraySummers http://forums.adobe.com/people/MurraySummers created the 
    discussion
    "Re: How do I find the FTP info for my site?"
    To view the discussion, visit: 
    http://forums.adobe.com/message/5993566#5993566

  • How do I find the phone # associated with my dryloop account?

    Customer service said they would be open til midnight but they're closed at 11:20. How do I find the phone # associated with my dryloop account so that I can pay online.

        Hi, yogaonmain!
    I'm sorry we were not available to get that information to you. Your mobile telephone number will be listed on your paper statement. It is also typically listed inside your phone under the Settings/Phone info section.
    If you need this information immediately, please call our customer service line at 800-922-0204.
    Thank you,
    AdamE_VZW
    Follow us on Twitter @VZWSupport

Maybe you are looking for

  • How to install Windows XP on my Pavilion dv6-6135dx

    (How to disable bios setting Native Sata) http://h10025.www1.hp.com/ewfrf/wc/document?docname=c01092639&tmp_track_link=ot_recdoc/c01172503/en_...

  • How do I add a folder of pdf files to itunes?

    Hi. I am preparing for my Ipad arriving next week. I have over 500 pdf files arranged in folders. I am trying to add them to my itunes library so as to sync to Ibooks but when I try adding a folder, nothing happens. I can add the files individually b

  • Am I putting to much pressure on my laptop?

    I'm running a macbookpro with a lot of stuff plugged in to it a lot of the time, I was just wondering if it's to much and might it be damaging the battery or anything else. Whats almost always plugged into it is the following; . usb powered midi keyb

  • Re:Upgrading from Business Connector to Xi

    Hi Guys, Can anybody plz help me how to upgrade from business connector ti XI Thanks in advance Hari

  • Watching YouTube on iPad...MP4 video format

    I have been watching YouTube on my iPad 2 for a long time.  I watch the videos from the full website instead of the app.  Recently, a YouTube channel that I've been watching for a long time changed the format of their videos, MP4, and now I can't wat