Article View: borland.public.jbuilder.java.swing
Article #8953Re: JPopupMenu problems
From: John P. McGrath
Date: Thu, 15 Jun 2000 00:00
Date: Thu, 15 Jun 2000 00:00
34 lines
1539 bytes
1539 bytes
On Wed, 14 Jun 2000 17:20:46 -0600, Janene McCrillis wrote:
> I need a popup menu that is dynamic, items come and go
> based on other events. As far as I can tell, one cannot
> remove items with JPopupMenu? Am I going to have to use
> the AWT popup?
popupMenu.addPopupMenuListener( new PopupMenuListener() {
public void popupMenuCanceled( PopupMenuEvent event ) {
}
public void popupMenuWillBecomeInvisible( PopupMenuEvent event ) {
}
public void popupMenuWillBecomeVisible( PopupMenuEvent event ) {
// Add or remove menu items here.
}
} );
> I also can't figure out how to intercept item selection
> at the menu level, rather than the item level perhaps
> adding the same listener to all items?
final SingleSelectionModel model = popupMenu.getSelectionModel();
model.addChangeListener( new ChangeListener() {
public void stateChanged( ChangeEvent event ) {
int index = model.getSelectedIndex();
// Handle the selection change.
}
} );
--
John P. McGrath
<JPMcGrath@fast.net>
<jpm@nscs.fast.net>
Technical Details
Message-ID:
<MPG.13b231789fcd78099899cf@forums.borland.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<3948134E.7E8B180C@indra.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111d45,47179425613a488b X-Google-Attributes: gid111d45,public From: John P. McGrath <JPMcGrath@fast.net> Subject: Re: JPopupMenu problems Date: 2000/06/15 Message-ID: <MPG.13b231789fcd78099899cf@forums.borland.com> X-Deja-AN: 634751037 References: <3948134E.7E8B180C@indra.com> Organization: Another Netscape Collabra Server User Newsgroups: borland.public.jbuilder.java.swing