-1

Am creating an MDI application .I have added all internalframe to desktoppane. My problem is to add all visible internal frames as menu items to "window" menu. and when another frame is selected from menu it should set focus. And i have to cal same from more than one time on desktop pane and each should be identical in menu item plzz help me I just add component listener and i call a function each time event created and the content of function is

enter code here
JCheckBoxMenuItem menu=new JCheckBoxMenuItem(); 
             String mnu = null;
             String title=null;
             for(int i=0;i<DesktopPane.getAllFrames().length;i++)
            {    int no=1;
                 JInternalFrame frame=(JInternalFrame) DesktopPane.getComponent(i);

                 String tit=frame.getTitle();
                 if(tit.contains(".")){
                    title=tit.substring(2,tit.length());
                 }
                 else{
                     title=tit;
                     }
                 if(windows.getItemCount()>0)
                  {
                    for(int j=0;j<windows.getItemCount();j++)
                    {
                         JCheckBoxMenuItem m=(JCheckBoxMenuItem) windows.getMenuComponent(j);
                         String s=m.getText();
                         String[] d=s.split(".",2);
                         String y=d[1];

                         if(y.equals("."+title))
                         {
                             if(j==0){
                             no=no-1;
                         }
                         no=no+1;
                     }
                }
                  mnu=no+"."+title;
              }
            else {
                  mnu=no+"."+title;
            }
          if(!frame.getTitle().contains(".")){
               frame.setTitle(no+"."+title);
          }
          menu.setText(mnu);
            buttonGroup1.add(menu);
            windows.add(menu);
            if(i==DesktopPane.getAllFrames().length-1)
            {
                 menu.setState(true);
             }
         }
}
Devu
  • 1
  • 3

2 Answers2

1

You could simply add a ContainerListener to the JDesktopPane. You would thus be notified each time an internal frame is added or removed to/from the JDesktopPane, and could thus modify the menu accordingly.

Each menu item of your menu could be associated with a JInternalFrame, and you would simply call setSelected(true) on the associated internal frame when a menu item is clicked.

JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255
0

I think you should take a look to this and this. Just call JDeskoptPane.getAllframes() to get the frames, and JInternalFrame.setSelected(true)to focus. To watch frame addition deletion, you could use a listener.

Vinz243
  • 9,654
  • 10
  • 42
  • 86
  • Answers containing links only are discouraged, and one of the links you provided points to a method that should not be called directly. Moreover, it doesn't answer the question. – JB Nizet Aug 20 '13 at 11:45