• Post Reply Bookmark Topic Watch Topic
  • New Topic

Closing a frame from another frame

 
Jeremy Jones
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have this problem. I open up a new frame from my main frame just fine, and I can get it to close when I press the x in the title bar. But I cannot get it to close by triggering an event on my main frame.
I have a menu, it has a CheckboxMenuItem, when I enable the check, it opens the frame, but when I disable the check, the frame does not close. I've tried the and . But these only seem to work for me when call those methods from the frame I wish to close.
Does anyone know how to do this?
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It could be something more specific in the change event of the MenuItem. could you post that part of the code please? What you provided really isn't enough to determine a solution.
 
Jeremy Jones
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

 
VIJAY Yadlapati
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here every time you are creating a new instance of ColorPicker in the toggleColorPicker() method, and when you are expecting to close the frame, you are closing the newly created Frame.
You should declare colWin as a class level variable (member of the class), rather than a local variable in the toggleColorPicker() method.
public Class
{
....
....
ColorPicker colWin=null;
....
....
....
....
public void toggleColorPicker(boolean blnCol)
{
if(blnCol==true)
{
if(colWin==null)
{
colWin=new ColorPicker();
colWin.setSize(100,100);
colWin.setResizable(false);
colWin.setTitle("Color Picker");
}
colWin.setVisible(true);
}
else
colWin.setVisible(false);
}
....
....
}
 
Jeremy Jones
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, I'll give it a shot
 
Jeremy Jones
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you, Thank you, Thank you
Works beautifully
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!