🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.language
Article #14726

re: Instantiating Dialog from a Menu

#14726
From: Johan Forsberg
Date: Thu, 05 Aug 1999 00:00
23 lines
1468 bytes
Jon C. Creyts <jcreyts@newton.berkeley.edu> skrev i
diskussionsgruppsmeddelandet:37A82854.622A082E@newton.berkeley.edu...
> Simple Q:
>
> What is the easiest way to identify the parent FRAME associated with a
> menu.  As a simple example, suppose I would like to instantiate a dialog
> box when a menu item is selected.  Constructing a new dialog box
> requires that a parent frame be identified.  If the menu is a class of
> its own, I need some way to reference the frame wherein the menu resides
> to create the dialog box.  Is there a function similar to getParent that
> allows you to do so?

Window w=SwingUtilities.windowForComponent(myMenuItem);

Better check that the Window is a Frame before you proceed...
Or you can use

Frame f=SwingUtilities.getAncestorOfClass(Frame.class, myMenuItem);

which may return null (if the window isn't a Frame).

Both methods work with any Component..
Technical Details
Message-ID: <7oc1eo$qss12@forums.borland.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <37A82854.622A082E@newton.berkeley.edu>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f74b3,3ff82da5ba67b967
X-Google-Attributes: gidf74b3,public
From: "Johan Forsberg" <jfo@stmf.se>
Subject: re: Instantiating Dialog from a Menu
Date: 1999/08/05
Message-ID: <7oc1eo$qss12@forums.borland.com>
X-Deja-AN: 509165719
References: <37A82854.622A082E@newton.berkeley.edu>
X-Priority: 3
X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2014.211
Organization: Another Netscape Collabra Server User
X-MSMail-Priority: Normal
Newsgroups: borland.public.jbuilder.java.language