File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Close currently opening JFrames which are opend in JInetrnalFrame Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Close currently opening JFrames which are opend in JInetrnalFrame" Watch "Close currently opening JFrames which are opend in JInetrnalFrame" New topic
Author

Close currently opening JFrames which are opend in JInetrnalFrame

Sham Usha
Greenhorn

Joined: Jul 22, 2001
Posts: 11
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.
Swati Udas
Ranch Hand

Joined: Aug 18, 2004
Posts: 121
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.


SCJP 1.4 (90%)<br />SCWCD 1.4 (88%)
Sham Usha
Greenhorn

Joined: Jul 22, 2001
Posts: 11
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

Joined: Aug 18, 2004
Posts: 121
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

Joined: Jul 22, 2001
Posts: 11
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

Joined: Aug 18, 2004
Posts: 121
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!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Close currently opening JFrames which are opend in JInetrnalFrame
 
Similar Threads
How can I use a javascript var in my jsp?
struts menu tooltip
How To Read Html Page Opened In Browser Using Java Program
Swing JFrame
mnemonics are not getting focus for the menubar