Article View: borland.public.jbuilder.java.swing
Article #12598Re: Menubar and JInternalFrame
From: Steve Waters
Date: Thu, 10 Dec 1998 00:00
Date: Thu, 10 Dec 1998 00:00
124 lines
4572 bytes
4572 bytes
1. JinternalFrame
2. a refererence to the frame
3 setJmenu bar.
it goes like this
code............
create internal frame
create object(pass frame)
more code
* note when this class (above) is destroyed or made null you will no longer have
a pointer to this object below, so make sure you destroy it too.
public create object(jinternalfrrame value)
blah
blah
set jmenu( value)
blah
Nadia Akrour wrote:
> Thanks for your answer. But I'm afraid I 'm missing some points :
> 1- You said you use menubar inside frames,do you mean JInternalFrame or just
> Frame ?
> 2 -What is the class type you pass the frame to ? Is it a class which extends
> JInternalFrame or a class with only a reference to the frame ?
> 3- How do you add the menubar to the frame ? Do you use setJMenuBar or just
> add(mymenubar) ?
> Thank you for all the help and explanation you can give me.
>
> For information here is the part of the code concerned. the main frame's
> method newDocument() adds an internal frame to the desktop pane. We create
> some MyInternalFrame objects and then close them. We call the GC and all are
> GCed. But this doesn't work if the MyInternalFrame contents a menubar.
>
> // main frame class
> public class TheFrame extends JFrame {
> JDesktopPane desktop;
> ...
> ...
> public void newDocument() {
> TheInternalFrame doc = new ThenternalFrame(this);
> desktop.add(doc, DOCLAYER);
> try {
> doc.setSelected(true);
> } catch (java.beans.PropertyVetoException e2) {}
> }
> }
>
> // internal frame class
> public class TheInternalFrame extends JInternalFrame implements
> InternalFrameListener{
> JMenuBar m_MenuBar;
> TheFrame m_f;
> ...
> static int openFrameCount = 0;
> ...
> public TheInternalFrame(TheFrame f) {
> super("", true, true, true, true);
> m_f = f;
> openFrameCount++;
> setTitle("Untitled Message " + openFrameCount);
>
> top = new JPanel();
> top.setBorder(new EmptyBorder(10, 10, 10, 10));
> top.setLayout(new BorderLayout());
>
> // Panel menubar
> m_MenuBar = new JMenuBar();
> setJMenuBar(m_MenuBar);
>
> setContentPane(top);
> pack();
> addInternalFrameListener(this);
> setLocation( offset * openFrameCount, offset *openFrameCount);
> }
>
> // ------------
> /** finalize */
> // ------------
> public void finalize() throws Throwable {
> System.out.println("TheInternalFrame " + getTitle() + " being GCed !");
> super.finalize();
> }
>
> // ------------
> /** dispose */
> // ------------
> public void dispose() {
> System.out.println("TheInternalFrame " + getTitle() + " disposed !");
> top.remove(m_MenuBar);
> m_MenuBar = null;
> top = null;
> m_f = null;
> super.dispose();
> }
>
> }
>
> Steve Waters wrote:
>
> > we use menubar inside frames, what we do is pass to the constructor of the
> > class the frame and then in the class we create the menubar and add it to
> > the frame, that way we can change the menu at any time, and set the class
> > object that create the menu to null to allow the garbage collector to free
> > up the memory. Works for us.
> >
> > Steve
> >
> > Nadia Akrour wrote:
> >
> > > Hi all,
> > > I would like to finalize internal frames.
> > > It works only when the internal frame does not contain a menu bar. It
> > > seems like the SetJMenuBar() function make the menu bar referenced by
> > > the frame (rootPane layaredPane or what ?) but how ? What can I do to
> > > break this link ?
> > > All my internal frames have a menu bar so they will not be freed and my
> > > appli will go out of memory quickly. So it's a very critical problem for
> > > me.
> > > Please any help would be very appreciated. Thanks in advance.
> > > Nad.
Technical Details
Message-ID:
<36703797.9F0BB1B4@bellsouth.net>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<366E5D45.9342BA14@spring.fr> <366F6314.73E5CDEE@bellsouth.net> <366FB425.C5E8333E@spring.fr>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111d45,7a1fee86da1b3c36 X-Google-Attributes: gid111d45,public From: Steve Waters <steve_w@bellsouth.net> Subject: Re: Menubar and JInternalFrame Date: 1998/12/10 Message-ID: <36703797.9F0BB1B4@bellsouth.net> X-Deja-AN: 420938708 Content-Transfer-Encoding: 7bit References: <366E5D45.9342BA14@spring.fr> <366F6314.73E5CDEE@bellsouth.net> <366FB425.C5E8333E@spring.fr> X-Accept-Language: en Content-Type: text/plain; charset=us-ascii Organization: Another Netscape Collabra Server User Mime-Version: 1.0 Newsgroups: borland.public.jbuilder.java.swing