• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Close currently opening JFrames which are opend in JInetrnalFrame

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In my JFrame main menu I have opened a JInternalFrame.
Within the JInternalFrame I have opend many JFrames.
I have closed button in the JInternalFrame only. There I can close only JInternalFrame. But I need to close all the opened JFrames as well other than the Menu.

Pls help me.
 
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you want to close all the existing windows you can add
systen.exit(); to the actionlistener for the close button..
else add appropriate listener from outer most frame and selectively close the required windows.
 
Sham Usha
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Swati

Once I used System.exit() then close the main menu also.
I need to close only the internal frame and the opened Jframes only.

To selectively close the required windows, how I can identify what are the opened jframes objects. Since there are several menues in the Main menu. and user can open only one internalfame at a time. There he may or may not be open jframes. If there are opened Jframes once he exit from that menu option all the opened Jframe and internal frame need to be closed other than main menu.
 
Swati Udas
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Sham Usha,

As far as I understand U have a close button in JInternalFrame.
Also u are instantiating the internal JFrames from the JInternal frame.
I think u should be able to check from the JInternalFrame for open JFrames and close them . Can you paste some part of the code, that will give a clearer idea about your problem.
 
Sham Usha
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Swati for u r interest on my probs
Here is the extracted main menu JFrame class


public class MainMenuGU extends JFrame implements ActionListener, ItemListener {
JInternalFrame intFrm;

public void setInternalFrame(JInternalFrame intFrameScreen,int width,int height){
if(intFrm!=null) intFrm.dispose();

intFrm=intFrameScreen;
ComponentUI frameUI = intFrm.getUI();
if (frameUI instanceof BasicInternalFrameUI) {
((BasicInternalFrameUI) frameUI).setNorthPane(null);
}


JButton cmdClose = new JButton();
cmdClose.setBorder(null);
cmdClose.setBounds(new Rectangle(width-30, 1, 17, 16));
cmdClose.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseReleased(MouseEvent e) {
intFrm.dispose();

}});

intFrm.getContentPane().add(cmdClose, null);
intFrm.pack();
intFrm.setSize(width,height);

contentPane.add(intFrm,null);
intFrm.setVisible(true);

}



public void actionPerformed(ActionEvent e){


Class clsOption = Class.forName("class name depend on option");
JInternalFrame jplOption = (JInternalFrame)clsOption.newInstance();
setInternalFrame(jplOption,jplOption.getWidth(),jplOption.getHeight());
this.getContentPane().add(jplOption);
jplOption.setVisible(true);

jplOption.requestDefaultFocus();

}

}
 
Swati Udas
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Sham Usha,
I read through your code..
I am not very sure how Jframes are created in side an JInternalFrame.
However I have a suggestion..
U have added a mouse listener to your close button..
U can also add actionlistener..

cmdclose.addActionListener(this);

Also go to you actionperformed function and recognise this event

public void actionPerformed(ActionEvent e){
if(e.getsource==cmdclose){
//write the code to close all the frames and internal Jframe
//I am not sure if u can catch the open frames at this point.
}

//Let ur existing code be as it is here
}


I have another suggestion too:
override the internalframe.dispose method and add lines to close all Frames from there- I havent worked with JInternalFrame..so i am not sure how JFrames are opened from here and if can access them from this dispose function.

Hope i have not confused you!!Let me know if this helps!
 
When people don’t understand what you are doing they call you crazy. But this tiny ad just doesn't care:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic