M
Martijn Mulder
I declare and define an instance of JMenu in the
constructor of my JFrame-class. Then I use
setJMenu(JMenu) to attach the menu to the
main window. It works well, I can use the
menu, I do not experience strange behavior.
But somehow I am concerned that the JMenu
no longer exists after program flow leaves the
constructor. Does the garbage collector remove
it and is it mere change that I have a menu, or
does the call to setJMenu keep the instance alive?
//class Instrument
public class Instrument extends javax.swing.JFrame
{
//constructor
public Instrument()
{
//call parent constructor
super(a);
//menubar
javax.swing.JMenuBar menubar=new javax.swing.JMenuBar();
//add items to menubar
//set JMenuBar
setJMenuBar(menubar);
}
}
constructor of my JFrame-class. Then I use
setJMenu(JMenu) to attach the menu to the
main window. It works well, I can use the
menu, I do not experience strange behavior.
But somehow I am concerned that the JMenu
no longer exists after program flow leaves the
constructor. Does the garbage collector remove
it and is it mere change that I have a menu, or
does the call to setJMenu keep the instance alive?
//class Instrument
public class Instrument extends javax.swing.JFrame
{
//constructor
public Instrument()
{
//call parent constructor
super(a);
//menubar
javax.swing.JMenuBar menubar=new javax.swing.JMenuBar();
//add items to menubar
//set JMenuBar
setJMenuBar(menubar);
}
}