Help about JInternalFrame......

Hello everybody...

i need help about JInternalFrame i know how to use it and how to create it but im facing a little problem is that i want to check that Internal frame already open or not and also want to know when we open another internal frame it open but behind already open frame how to bring it infront....ill be thankful for givin me solution.....

[367 byte] By [zerocooola] at [2007-11-26 12:40:10]
# 1

> i want to check that Internal frame already open or not

What does this mean? Do you mean is it iconified or not.

> and also want to know when we open another internal frame it open but behind already open frame how to bring it infront

Read the Swing tutorial on [url http://java.sun.com/docs/books/tutorial/uiswing/components/internalframe.html]How to Use Internal Frames[/url] for a working example.

camickra at 2007-7-7 16:11:14 > top of Java-index,Desktop,Core GUI APIs...
# 2

hi thanx for reply let me tell u by an little example..i have 4 internal frame i click on menu to open frame 1, mean while i open frame 2 again i got to menu and press frame 1 menu it not to create another instance of frame 1 just tell me frame 1 is already open or bring in front......of frame 2 or any other frame.....

now my second problem is that like above example.....that i have setted the size of the all frames which is different some are in small size some are little bing size.....i have open frame 1 which is big size.....and i got to menu again and open frame 2 which is small size and open behind the fram1 i want to know how can i solve this problem when i call any new frame should be infront of already open frams.....

thanx.....for giving sloutions...

zerocooola at 2007-7-7 16:11:14 > top of Java-index,Desktop,Core GUI APIs...
# 3

Re your first point, you can use a map to do this. Identify "open a window" requests by a key - a simple identifying object - the desktop manager can keep a map of keys to frames. Don't forget to remove the entries when frames are closed.

Re the second point, JInternalFrame has toFront() and setSelected() methods, you will need to call these.

itchyscratchya at 2007-7-7 16:11:14 > top of Java-index,Desktop,Core GUI APIs...
# 4

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

public class forZerocool extends JFrame implements ActionListener{

JMenuBar menuBar;

JMenu menuOpen;

JMenuItem itemOF1, itemOF2, itemOF3, itemOF4;

JDesktopPane desk;

forZerocool(){

setDefaultCloseOperation(EXIT_ON_CLOSE);

desk=new JDesktopPane();

menuBar=new JMenuBar();

menuOpen=new JMenu("Open");

menuOpen.setMnemonic(KeyEvent.VK_O);

menuBar.add(menuOpen);

itemOF1=new JMenuItem("Open Frame1",KeyEvent.VK_1);

itemOF2=new JMenuItem("Open Frame2",KeyEvent.VK_2);

itemOF3=new JMenuItem("Open Frame3",KeyEvent.VK_3);

itemOF4=new JMenuItem("Open Frame4",KeyEvent.VK_4);

menuOpen.add(itemOF1);

menuOpen.add(itemOF2);

menuOpen.add(itemOF3);

menuOpen.add(itemOF4);

itemOF1.addActionListener(this);

itemOF2.addActionListener(this);

itemOF3.addActionListener(this);

itemOF4.addActionListener(this);

setJMenuBar(menuBar);

setContentPane(desk);

setSize(600,600);

setVisible(true);

}

public void actionPerformed(ActionEvent ae){

/*The important thing is you set Name to the internal frame using

the setName method so we can easily find it out later whether it any frame in that name already exists*/

if(ae.getActionCommand().equals("Open Frame1")){

System.out.println("hai");

System.out.println("total components on the desk ="+desk.getComponentCount());

if(desk.getComponentCount()>0){

for(int i=0;i<desk.getComponentCount();i++){

System.out.println("comp"+i+"="+desk.getComponent(i).getName());

if(desk.getComponent(i).getName().equals("IFrame1")){

JOptionPane jop=new JOptionPane();

jop.showMessageDialog(this,"Frame already exists -will come to front");

JInternalFrame jf=(JInternalFrame)desk.getComponent(i);

jf.toFront();

try {

jf.setSelected(true);

} catch (java.beans.PropertyVetoException e) {}

return;

}

}

}

JInternalFrame iframe1=new JInternalFrame("Frame1",true,true,true,true);

iframe1.setName("IFrame1");

iframe1.setSize(200,100);

iframe1.setLocation(10,10);

iframe1.setVisible(true);

iframe1.toFront();

desk.add(iframe1);

try {

iframe1.setSelected(true);

} catch (java.beans.PropertyVetoException e) {}

}

else if(ae.getActionCommand().equals("Open Frame2")){

System.out.println("hai");

JInternalFrame iframe2=new JInternalFrame("Frame2",true,true,true,true);

iframe2.setName("IFrame2");

iframe2.setSize(200,100);

iframe2.setLocation(20,40);

iframe2.setVisible(true);

iframe2.toFront();

desk.add(iframe2);

try {

iframe2.setSelected(true);

} catch (java.beans.PropertyVetoException e) {}

}

}

public static void main(String args[]){

new forZerocool().setVisible(true);

}

}

I am wondering, out of the maximum ten marks, how many marks this program is going to fetch from you?>

pravintha at 2007-7-7 16:11:14 > top of Java-index,Desktop,Core GUI APIs...
# 5
very thanx pravinth its really work. and really really thanxx. very much helpfull code example.now can u give me another example that bring front already open internalframe to other frames.... again really very thanx
zerocooola at 2007-7-7 16:11:14 > top of Java-index,Desktop,Core GUI APIs...
# 6

First Thank you very much for the dukes.. You are really great...

Sorry zerocoool- i can't undesrtand your request....

>>.now can u give me another example that bring front already open internalframe to other frames

In that above program i used the toFront() method of an internal frame to take it to the front... so i can't understand what do you want still?

please explain your request little bit more clearly..please....

Thank You again....

pravintha at 2007-7-7 16:11:14 > top of Java-index,Desktop,Core GUI APIs...
# 7
i want this that where ur viewing message about Frame already open i want to bring already open window in front.....or if it is in minimize form than bring it in front......
zerocooola at 2007-7-7 16:11:14 > top of Java-index,Desktop,Core GUI APIs...
# 8

Don't use:

for(int i=0;i<desk.getComponentCount();i++)

to get the internal frames. Not every component on the desktop will be an internal frame. For example if you iconify a frame you will find a JInternalFrame.JDesktopIcon. Instead use this method from the JDesktopPane:

getAllFrames();

Then when you select the internal frame you can also use the following:

jf.setIcon( false );>

camickra at 2007-7-7 16:11:14 > top of Java-index,Desktop,Core GUI APIs...