Article View: borland.public.jbuilder.java.swing
Article #12591Re: Menubar and JInternalFrame
From: Nadia Akrour
Date: Thu, 10 Dec 1998 00:00
Date: Thu, 10 Dec 1998 00:00
105 lines
3901 bytes
3901 bytes
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:
<366FB425.C5E8333E@spring.fr>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<366E5D45.9342BA14@spring.fr> <366F6314.73E5CDEE@bellsouth.net>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111d45,7a1fee86da1b3c36 X-Google-Attributes: gid111d45,public From: Nadia Akrour <akrour@spring.fr> Subject: Re: Menubar and JInternalFrame Date: 1998/12/10 Message-ID: <366FB425.C5E8333E@spring.fr> X-Deja-AN: 420772440 Content-Transfer-Encoding: 7bit References: <366E5D45.9342BA14@spring.fr> <366F6314.73E5CDEE@bellsouth.net> X-Accept-Language: fr-FR,en Content-Type: text/plain; charset=us-ascii Organization: SPRING TECHNOLOGIES Mime-Version: 1.0 Newsgroups: borland.public.jbuilder.java.swing