tags:

views:

32

answers:

1

I re-structured the question: There is a picture of this code that works.

all the code works fine. what is in question is a few lines in each block of code. so the setters and the last block of code need attention.

Is there an error the logic in my JDesktopPane because I think I am creating and setting the JInternalFrame and the JTabbedPane and trying to reference them in another class

so how should I reference the JTabbedPane ?

problem overview: The user logs in and a JInternalFrame holds a Jpanel. The JPanel holds a JTabbedPane with 11 tabs on it. The JInernalFame has a menu. The user has the 11 tabbed window open they click menuItem to build the same structured frame but with only two tabs on it. The problem is when they try to return to the 11 tabbed Pane via the menuItem the progam can not set the index to the 8th tab.

How do I reference this JInternalFrame or the JPanel or the JTabbedPane to allow the Menu to perform the action correctly?

create and set the InternalFrame SchoolJDesktopPane.java this defiantly creates the InternalFrame so I set it as shown in bold

This code does what it is supposed to do so I set the setter setCurrentContentPane(contentPane);

 public void createInnerFrame(String thisLn) throws IOException, FileNotFoundException, SQLException, ProfileException, LoginException, javax.security.auth.login.LoginException, UnknownUserNameException, IncorrectPasswordException, SuccessfullTargetFoldersCreation {

    ln = thisLn;
    String colon = (" :");
    ln.concat(colon);
    setGuideName(ln);
    JPanel contentPane = new JPanel(new BorderLayout());
    SetObjects so = new SetObjects();
    SetObjects.setType("guide");
    profile = ViewUtils.getProfile();
    SetObjects.initPanelComponents();
    contentPane.add(SetObjects.obj());//sets the JTabbedPane that was created on JPanel
    frame = new InternalFrame();
    int inset = 0;
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    setBounds(inset, inset, screenSize.width - inset * 2, screenSize.height - inset * 2);
    //frame.setBounds(inset, inset, screenSize.width - inset * 10, screenSize.height - inset * 25);
    //substandard//////////////////////////////////       
    frame.add(contentPane);//puts JPanel on Frame
     setCurrentGuide(frame);
     ****setCurrentContentPane(contentPane);****
    jdp.add(frame);

}//end CreateNewGuide;

create and set the JTabbedPane SetObjects.java this defiantly creates the JTabbedPane so I set it as shown in bold

This code does what it is supposed to do so I set the setter ** setCurrentJTabbedPane(currentJTabbedPane);**

if (type.equals("guide")) {

        i = 0;
        z = 0;
        go = 0;
        int index = 0;
        tabMap=new ArrayList();
        TabControl tc =new TabControl();

        if (guideTabLabels.length > 0) {
            while (go < guideTabLabels.length) {
                tabName = guideTabLabels**;
                jtp.addTab(guideTabLabels[z], null, guideJPanel());
                jtp.setSelectedIndex(index);                    
                jtp.setName(tabName);

                tabMap.add(tabName);
                boolean enable=tc.initTabControl(index);                   
                if(enable==true){
                    jtp.setEnabledAt(index,true);
                }
                if(enable==false){
                    jtp.setEnabledAt(index,false);
                }
                index++;

            }
            CreateSystemStartFolders ctf=new CreateSystemStartFolders();
            ctf.setupUserFolder();
        }

        jtp.setSelectedIndex(0);
       **** setCurrentJTabbedPane(currentJTabbedPane);****

    }

AdminAction.java extends AbstractAction

The menuItem is slected after the SetObects.java has created a different JInternalFrame and now it is to return back to the original frame and perform and action

This code does what it is supposed to do so I call ** mca.controlJMenuItems(e);**

    public class AdminAction extends AbstractAction {



    private String name;

    public AdminAction(String name) {
        super();
        CreateInnerFrameMenuAdmin.actionsRegister.setActionCommand(name);


    }
    private boolean bReset;
    private String searchField;
    private boolean bNewUser;

    public void actionPerformed(ActionEvent e) {


        String M =(" --> in actionPerformed("+e.getActionCommand()+") \n var:   e.getActionCommand() : xxxxxxxx<-- \n");
       System.out.println(M);

       System.out.println(C+M+AND+name+": var name: : : \n");
        if (e.getSource() == CreateInnerFrameMenuAdmin.actionsRegister) {

             System.out.println(C+M+AND+name+": var name: : in the actionPerformed : \n");
            try {
                JMenuControlAdmin mca = new JMenuControlAdmin();
                mca.actionsRegisterActions();
                System.out.println(C+M+AND+": caller \n--->: mca.controlJMenuItems("+e.getActionCommand()+") : var: e.getActionCommand()  :  <-----\n");
               ** mca.controlJMenuItems(e);**
            } catch (ProfileException ex) {

                  Logger.getLogger(CreateInnerFrameMenuAdmin.class.getName()).log(Level.SEVERE, null, ex);
           ....
        }
    }
    /** Returns an ImageIcon, or null if the path was invalid. */
 }

JMenuControlAdmin.java

This code works all the way up to when I try to set the index on the JTabbedPane that I am trying to reference.

> ......... ..............

     public JMenuControlAdmin() throws FileNotFoundException, IOException {


        String M =(" --> in JMenuControlAdmin() <-- \n");
      System.out.println(M);
        if (profile.equals("admin_")) {
            JInternalFrame frame= SchoolJDesktopPane.getCurrentGuide();

            setFrame(frame);
            REGISTERINDEX = "adminRegister.index";

            //MyKeyFactory mkf =new MyKeyFactory();
        }
...........
..........

 public JMenuControlAdmin() throws FileNotFoundException, IOException {


        String M =(" --> in JMenuControlAdmin() <-- \n");
      System.out.println(M);
        if (profile.equals("admin_")) {**
            frame= SchoolJDesktopPane.getCurrentGuide();
            pane= SetObjects.getCurrentJTabbedPane();**
            setFrame(frame);
            setPane(pane);
            REGISTERINDEX = "adminRegister.index";

            //MyKeyFactory mkf =new MyKeyFactory();
        }

...........
...................

 public void controlJMenuItems(ActionEvent e) throws FileNotFoundException, IOException {


        String M =(" --> in controlJMenuItems("+e.getActionCommand()+") \n var: e.getActionCommand() : xxxxxxxx<-- \n");
       System.out.println(M);

        System.out.println("profile from setObjects in control: " + profile);
        MyKeyFactory kf = new MyKeyFactory();
        SetObjects so = new SetObjects();
        so.setType("guide");
        so.initPanelComponents();
        if (profile.equals("admin_")) {
            if (e.getActionCommand().equals("actionsRegister")) {
                //enable menu items
                CreateInnerFrameMenuAdmin.navigateRegister.setEnabled(true);
                CreateInnerFrameMenuAdmin.navigateGlossary.setEnabled(true);
                CreateInnerFrameMenuAdmin.navigateAdministrator.setEnabled(true);
                //enable tabs
                String strIndex = ViewUtils.getResource(REGISTERINDEX);
                int index = Integer.parseInt(strIndex);

                 M =(" --> in controlJMenuItems("+e.getActionCommand()+") var: e.getActionCommand() : xxxxxxxx<-- \n");
                 System.out.println(M);


                **jtp=getPane();**
                **jtp.setSelectedIndex(index);**

**why isn't this the  JTabbedPane from when it was create and set and now being referenced?**

                  /*
                SetObjects.jtp.setSelectedIndex(index);

                SetObjects.jtp.setEnabledAt(index, true);
                   *
                   */
                int count =jtp.getTabCount();
                 System.out.println(C+M+AND+count+": var: count : \n");
            }

output

CLASS AdminAction: --> in actionPerformed(actionsRegister) var: e.getActionCommand() : xxxxxxxx<-- : : caller --->: mca.controlJMenuItems(actionsRegister) : var: e.getActionCommand() : <-----

--> in controlJMenuItems(actionsRegister) var: e.getActionCommand() : xxxxxxxx<--

profile from setObjects in control: admin_ tabCount at tlaa: admin_guideTab.total tlaa get vu.getResource: tabCount: 11 --> in controlJMenuItems(actionsRegister) var: e.getActionCommand() : xxxxxxxx<--

    at **view.menus.innerframe.admin.JMenuControlAdmin.controlJMenuItems(JMenuControlAdmin.java:133)
    at view.menuActions.AdminAction.actionPerformed(AdminAction.java:98)**
    at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
    at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
    at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
    at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
    at javax.swing.AbstractButton.doClick(AbstractButton.java:357)
    at javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:1223)
    at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(BasicMenuItemUI.java:1264)
    at java.awt.Component.processMouseEvent(Component.java:6267)
    at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
    at java.awt.Component.processEvent(Component.java:6032)
    at java.awt.Container.processEvent(Container.java:2041)
    at java.awt.Component.dispatchEventImpl(Component.java:4630)
    at java.awt.Container.dispatchEventImpl(Container.java:2099)
    at java.awt.Component.dispatchEvent(Component.java:4460)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4577)
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
    at java.awt.Container.dispatchEventImpl(Container.java:2085)
    at java.awt.Window.dispatchEventImpl(Window.java:2478)
    at java.awt.Component.dispatchEvent(Component.java:4460)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
A: 

The posted code shows specific classes. If I create a JInternalFrame or a JTabbedPane and put them in a setter then why can't I reference it with.

jtp=SetObject.getCurrentJTabbedPane();
jtp.setSelectedIndexAt(index,true);
ceyesumma