Hi I was wondering if there is a way to set a jbutton to do the equivalent of setdefaultcloseoperation(JFrame.DISPOSE_ON_CLOSE) because I dont understand how a frame object is eligible for collection if it still has listeners when the frame is set invisible. I can send code if this doesn't make sense.
Asked
Active
Viewed 351 times
3
-
1Explain a bit more. I can't see what you're asking here. – ApprenticeHacker Apr 23 '12 at 05:45
-
Just in the `actionPerformed(...)` method of your so called `JButton` write `frameObject.dispose();`, that will give you, your equivalent behaviour :-) – nIcE cOw Apr 23 '12 at 05:47
-
Hehe, You're MOST WELCOME and KEEP SMILING :-) – nIcE cOw Apr 23 '12 at 05:51
2 Answers
2
Top Level Containers (
JFrame
,JDialog
...) miss implemetations forfinalize()
, then they are never GC'dequivalent for
JFrame.DISPOSE_ON_CLOSE
is onlysetVisible(false)
you can returns all Top Level Containers from method
Window[] wins = Window.getWindows();
you can remove only all
JComponents
fromContentPane
, for return used memory back
EDIT
- only visible container with
Focus
can listening or firing events from Swing Listeners
-
+1, this info is always true, no one has the power to control GARBAGE COLLECTION :-), but wont' writing dispose(), will atleast make it available for the GC to collect it, though only JVM can tell as to when will that happen. – nIcE cOw Apr 23 '12 at 06:00
-
ya thats what i thought. so does setVisible(false) leave the frames listeners open? thus not making the frame eligible for gc? – Ben Evans Apr 23 '12 at 07:24
-
that make sense. just so i know i have understood your edit, is Focus what setVisible(bool) turns on and off? – Ben Evans Apr 23 '12 at 08:25
1
addActionListener( new ActionListener(){
public void actionPerformed(ActionEvent e){
myframe.dispose();
}
});

ApprenticeHacker
- 21,351
- 27
- 103
- 153