Hello.
I have an app (JDesktop) and it has the JMenu and some JMenuItems. One will build an JTabbedPane with a dozen or so tabs. I start that one and it works good. Another MenuItem
builds another Internal Frame with JtabbedPanels it works too. When I go back to the JDesktop Menu and try to work with the firs InternalFrame with more JTabbes It won't work because the Menu is still working with the other Frame. Is there a way to keep them JDesktop menu in sync with what frame has the focus?
Thanks

Recommended Answers

All 11 Replies

Typically a menu item's action is handled in some Action class (extends AbstractAction). So you might have one class called something like BuildTabbedPaneAction that extends AbstractAction and another called BuildInternalFrameAction that also extends AbstractAction. Each of these classes implements the actionPerformed method to "do its thing". When the Actions are created to be placed on a menu, you can pass an instance of the app (JDesktop) to the Action's constructor so that the Action has a way of communicating with the app.

In your application (JDesktop) you can have a variable called something like currentFrame, and public getter (getCurrentFrame) and setter (setCurrentFrame) methods that can be called by other classes.

Now in both BuildTabbedPaneAction's actionPerformed method and BuildInternalFrameAction's actionPerformed method, each one can call setCurrentFrame on the app to say which frame is currently being worked on. Then when the app (or other class) needs to know which frame is active, it can call the getCurrentFrame method.

Each of these classes implements the actionPerformed method to "do its thing". When the Actions are created to be placed on a menu, you can pass an instance of the app (JDesktop) to the Action's constructor so that the Action has a way of communicating with the app.

Totally new concept. Thanks I will have to go thru my code to see how I can implement this.
I don't really understand it yet. If I could find a code example that would be great.
any ideas of a google key word that could generate some links? I will have to get back to
you once I try to implement something into the app.

Try java AbstractAction MenuItem example Here's one link I found.

Hello
The only thing that makes sense at the moment is to set the frame when I create it as it will
be the main window for the user that logged in.

Please find attached a screen shot of JDesktop.

JDesktopPane="Guide DesktopPane"
Main internal frame="Music Systems:1
note internal frame= "first note"


Main internal frame="Music Systems:1

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
        [b]setCurrentGuide((InternalFrame) frame);[/b]
        jdp.add(frame);

    }//end CreateNewGuide;

if the user decides to create a note it will create a new InternalFrame
and I suppose I might need to use a listener to control the frames here to
but for now I would like to know how to keep the main frame accessible.
note internal frame= "first note"

public static void createNotesInnerFrame(String ln) throws IOException, FileNotFoundException, SQLException, ProfileException, LoginException, javax.security.auth.login.LoginException, model.err.LoginException, UnknownUserNameException, IncorrectPasswordException, SuccessfullTargetFoldersCreation {

        String colon = (" :");
        ln.concat(colon);

        JPanel contentPane = new JPanel(new BorderLayout());
        SetObjects so = new SetObjects();
        SetObjects.setType("notes");
        profile = ViewUtils.getProfile();
        SetObjects.initPanelComponents();
        contentPane.add(SetObjects.obj());//sets the JTabbedPane that was created on JPanel
        String notes = "notes";
        frame = new InternalFrameNotes(ln);

        frame.add(contentPane);//puts JPanel on Frame

        SchoolJDesktopPane.setFrame(frame);

    }//end CreateNewGuide;

Then if the user returns to the main InternalFrame and use the menuitem to navigate to
the desired tab of it's internalframe it is still using the second InternalFrames structure
]
error

CLASS 
 ConnectAdminDAO: 
isAuthorizeAdmin(String name, String password) : false:  bCheck : returns :
JMenuControlAdmin: CheckNewUser(String searchField) : false: bNewUser : returns :
profile from setObjects in control: admin_
tabCount at tlaa: admin_guideTab.total
tlaa get vu.getResource: tabCount: 11
        at javax.swing.JTabbedPane.checkIndex(JTabbedPane.java:1738)
        at javax.swing.JTabbedPane.setSelectedIndex(JTabbedPane.java:572)
        at view.menus.innerframe.admin.JMenuControlAdmin.controlJMenuItems(JMenuControlAdmin.java:90)
        at view.menus.innerframe.admin.CreateInnerFrameMenuAdmin$16.actionPerformed(CreateInnerFrameMenuAdmin.java:473)
        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)

I know it is a feeble attempt to somehow keep the MenuItems and InternalFrames in sync
Is there a recommended approach to controlling menuItems and InternalFrames?
I don't think I can use an abstract Action class here.


I started by locating where the action was that was being called and tried to tell it which frame
to use. It's the wrong method though

///////////////////////////////////////////////////////////////////
        ////// actions ////////////    Register  /////////////////////////////
        ///////////////////////////////////////////////////////////////////
        actionsRegister = new JMenuItem();
        actionsRegister = (JMenuItem) jMenuActions.add(new JMenuItem("actions Register"));
        actionsRegister.setActionCommand("actionsRegister");
        jMenuActions.addSeparator();
        //newFile.setMnemonic('N');       
        //actionsList.add(name);

        actionsRegister.addActionListener(new ActionListener() {

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

            public void actionPerformed(ActionEvent e) {
                if (e.getSource() == actionsRegister) {
                    try {
                        JMenuControlAdmin mca = new JMenuControlAdmin();
                        mca.actionsRegisterActions();
                        mca.controlJMenuItems(e);[b]
                        JInternalFrame current=SchoolJDesktopPane.getCurrentGuide();
                        current.setEnabled(true);[/b]


                    } catch (ProfileException ex) {
                        Logger.getLogger(CreateI ........

When you do actionsRegister.addActionListener(new ActionListener() ... you are creating an unnamed class to handle the action. If instead you make it a named class, then it can have its own constructor, and you can pass in whatever information you need to maintain the correct state. My original post suggested that you could pass a reference to your application into the action. That way you can create methods in your application concerning state (such as which is the currently active frame) and those methods can be called by the action, because the action has a reference to the application.

Why are you saying it's the wrong method?

When you do actionsRegister.addActionListener(new ActionListener() ... you are creating an unnamed class to handle the action. If instead you make it a named class, then it can have its own constructor, and you can pass in whatever information you need to maintain the correct state. My original post suggested that you could pass a reference to your application into the action. That way you can create methods in your application concerning state (such as which is the currently active frame) and those methods can be called by the action, because the action has a reference to the application.

Why are you saying it's the wrong method?

I was saying the setEnabled() I used was not even close. It is a little clearer. Now If I do make this an abstract class I am not sure how to to tell it what it needs. When It is created it gets resources to tell it the tab count and the tab names to build it. (the main InternalFrame). The error says it is using the "notes frame" tab count. I am not sure what to do to use the InternalFrame that was created and is in a setter. in the JDesktop.getCurrentGuide(); I will have to re visit the link you supplied to see if it makes a little more sense now.

Hello again

I blindly changed my action to resemble what little code example I have could you look at
the JTabbedPane on the InternalFrame in question. I Passed the frame through and it might work
(if you criticthe actionPerformed structure)and if you could describe how I can reference the
index to the JTabbed Pane on the JInternalFrame passed.

///////////////////////////////////////////////////////////////////
        ////// actions ////////////    Register  /////////////////////////////
        ///////////////////////////////////////////////////////////////////
        actionsRegister = new JMenuItem();
        actionsRegister = (JMenuItem) jMenuActions.add(new JMenuItem("actions Register"));
        actionsRegister.setActionCommand("actionsRegister");
        jMenuActions.addSeparator();
        //newFile.setMnemonic('N');       
        //actionsList.add(name);

        actionsRegister.addActionListener(new AdminFrameActionImpl());

The new abstractAction class

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package view.menuActions;

import java.awt.event.ActionEvent;
import java.beans.PropertyVetoException;
import java.io.FileNotFoundException;
......
/**
 *
 * @author Steve's
 */
public class AdminFrameAction extends AbstractAction {

    public JInternalFrame frame;
    public AdminFrameAction()throws FileNotFoundException,model.......
    }
    public void actionPerformed(ActionEvent ae) {
        ...
            resetFrame(ae,frame);
       ....
    }

    public void resetFrame(ActionEvent ae,JInternalFrame frame) throws ProfileException, ..... {


                        JMenuControlAdmin mca = new JMenuControlAdmin();
                        mca.actionsRegisterActions();
                       [b] mca.controlJMenuItems(ae,frame);[/b]
                        JInternalFrame current=getFrame();
                        current.grabFocus();



    }

    public JInternalFrame getFrame() {
        return frame;
    }

    public void setFrame(JInternalFrame frame) {
        this.frame = frame;
    }


}

The Class that handles the menu of the specific JInternalFrame
the reference to the index of the JTabbedPane (error) is here

...
 public void controlJMenuItems(ActionEvent e,JInternalFrame frame) throws FileNotFoundException, IOException {
        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);
   error -->[b] JTabbedPane jtp=(JTabbedPane) frame.getContentPane().getComponent(0);[/b]
                jtp.setSelectedIndex(index);
                jtp.setEnabledAt(index,true);
                //SetObjects.jtp.setSelectedIndex(index);
                //SetObjects.jtp.setEnabledAt(index, true);

            }

...

The error

at view.menus.innerframe.admin.JMenuControlAdmin.controlJMenuItems(JMenuControlAdmin.java:92)
        at view.menuActions.AdminFrameAction.resetFrame(AdminFrameAction.java:110)
        at view.menuActions.AdminFrameAction.actionPerformed(AdminFrameAction.java:51)
        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)

It is not getting the frame that I set with the static setter and I don't know what to do to get the JTabbedPane tabs on it to set the index

any code before this post is junk code don't bother with it.thanks. starting over.

How can I get a reference to the JTabbedPane on this frame so I can set the index?

Set the frame needed

///////////////////////////////////////////////////////////////////
        ////// actions ////////////    Register  /////////////////////////////
        ///////////////////////////////////////////////////////////////////
        actionsRegister = new JMenuItem();
        actionsRegister = (JMenuItem) jMenuActions.add(new JMenuItem("actions Register"));
        actionsRegister.setActionCommand("actionsRegister");
        jMenuActions.addSeparator();
        //newFile.setMnemonic('N');       
        //actionsList.add(name);
        actionsRegister.addActionListener(new view.menuActions.AdminAction("actionsRegister"));

Looks like if I could get the JTabbed Pane on the frame I passed the propper index could be set

CLASS 
 xxxxxxxxxxxxxxxxxxxxxxxxxx: 
CheckNewUser(String searchField) : false: bNewUser : returns :
CLASS 
 AdminAction: 
 --> in actionPerformed(java.awt.event.ActionEvent[ACTION_PERFORMED,cmd=actionsRegister,when=1288060467975,modifiers=Button1] on javax.swing.JMenuItem[,1,3,117x21,invalid,alignmentX=0.0,alignmentY=0.0,border=javax.swing.plaf.metal.MetalBorders$MenuItemBorder@107e9a8,flags=264,maximumSize=,minimumSize=,preferredSize=,defaultIcon=,disabledIcon=,disabledSelectedIcon=,margin=javax.swing.plaf.InsetsUIResource[top=2,left=2,bottom=2,right=2],paintBorder=true,paintFocus=false,pressedIcon=,rolloverEnabled=false,rolloverIcon=,rolloverSelectedIcon=,selectedIcon=,text=actions Register]) 
 var: ActionEvent e : xxxxxxxx<-- 
 : : caller 
--->: mca.controlJMenuItems(java.awt.event.ActionEvent[ACTION_PERFORMED,cmd=actionsRegister,when=1288060467975,modifiers=Button1] on javax.swing.JMenuItem[,1,3,117x21,invalid,alignmentX=0.0,alignmentY=0.0,border=javax.swing.plaf.metal.MetalBorders$MenuItemBorder@107e9a8,flags=264,maximumSize=,minimumSize=,preferredSize=,defaultIcon=,disabledIcon=,disabledSelectedIcon=,margin=javax.swing.plaf.InsetsUIResource[top=2,left=2,bottom=2,right=2],paintBorder=true,paintFocus=false,pressedIcon=,rolloverEnabled=false,rolloverIcon=,rolloverSelectedIcon=,selectedIcon=,text=actions Register]) : var: e  :  <-----
[b]
Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: javax.swing.JRootPane cannot be cast to javax.swing.JTabbedPane[/b]
 --> in controlJMenuItems(java.awt.event.ActionEvent[ACTION_PERFORMED,cmd=actionsRegister,when=1288060467975,modifiers=Button1] on javax.swing.JMenuItem[,1,3,117x21,invalid,alignmentX=0.0,alignmentY=0.0,border=javax.swing.plaf.metal.MetalBorders$MenuItemBorder@107e9a8,flags=264,maximumSize=,minimumSize=,preferredSize=,defaultIcon=,disabledIcon=,disabledSelectedIcon=,margin=javax.swing.plaf.InsetsUIResource[top=2,left=2,bottom=2,right=2],paintBorder=true,paintFocus=false,pressedIcon=,rolloverEnabled=false,rolloverIcon=,rolloverSelectedIcon=,selectedIcon=,text=actions Register]) 
 var: e : xxxxxxxx<-- 

profile from setObjects in control: admin_
tabCount at tlaa: admin_guideTab.total
tlaa get vu.getResource: tabCount: 11
        at view.menus.innerframe.admin.JMenuControlAdmin.controlJMenuItems(JMenuControlAdmin.java:124)
        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)

AdminAction extends AbstractAction

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+") \n var: ActionEvent e : 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+") : var: e  :  <-----\n");
               [b] mca.controlJMenuItems(e);[/b]
            } catch (ProfileException ex) {
                Logger.getLogger(CreateInnerFrameMenuAdmin.class.getName()).log(Level.SEVERE, null, ex);
            } catch (ClassNotFoundException ex) {
                Logger.getLogger(CreateInnerFrameMenuAdmin.class.getName()).log(Level.SEVERE, null, ex);
           ....
        }
    }

menu controler

public JMenuControlAdmin() throws FileNotFoundException, IOException {


        String M =(" --> in JMenuControlAdmin() <-- \n");
      System.out.println(M);
        if (profile.equals("admin_")) {
            JInternalFrame frame= SchoolJDesktopPane.getCurrentGuide();
           [b] setFrame(frame);[/b]
            REGISTERINDEX = "adminRegister.index";

            //MyKeyFactory mkf =new MyKeyFactory();
        }
        if (profile.equals("stu_")) {
            REGISTERINDEX = "studentRegi........................


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


        String M =(" --> in controlJMenuItems("+e+") \n var: e : 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);
error --------> [b]JTabbedPane jtp = (JTabbedPane) frame.getComponent(0);[/b]
                jtp.setSelectedIndex(index);
                jtp.setEnabledAt(index, true);
                //SetObjects.jtp.setSelectedIndex(index);
                //SetObjects.jtp.setEnabledAt(index, true);
            }

Hello

I have implemented the Abstract Action AdminAction.java

I have a reference to the JTabbedPane passed to this action

I am trying to select a menuItem that will navigate to a tab
on the JTabbedPanes.

the JTabbedPane is on a JPanel that is on an JIternalFrame.

This JInternalFrame loses focus and when I select the JMenuItem on the InternalFrame
it is to move to a differnt tab using an index.

I don't know what the error is telling me.

AdminAction.java

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");
                [b]mca.controlJMenuItems(e);[/b]
            } 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

public class JMenuControlAdmin extends SetObjects implements ActionListener {

    public String REGISTERINDEX;
    public boolean bNewUser;
    public boolean bValid;
    public boolean bReset;
    public String searchField;
    public static JInternalFrame frame;

    public JMenuControlAdmin() throws FileNotFoundException, IOException {


        String M =(" --> in JMenuControlAdmin() <-- \n");
      System.out.println(M);[b]
        if (profile.equals("admin_")) {
            JInternalFrame frame= SchoolJDesktopPane.getCurrentGuide();
            setFrame(frame);
            REGISTERINDEX = "adminRegister.index";

            //MyKeyFactory mkf =new MyKeyFactory();
        }[/b]
        if (profile.equals("stu_")) {
            REGISTERINDEX = "studentRegister.index";
        }
        if (profile.equals("instr_")) {
            REGISTERINDEX = "instructorRegister.index";
        }
        if (profile.equals("payee_")) {
            REGISTERINDEX = "payeeRegister.index";
        }
    }

    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();
       [b] if (profile.equals("admin_")) {[/b]
            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);
              [b]
                JTabbedPane jtp = SetObjects.getCurrentJTabbedPane();
                
                //jtp.grabFocus();
                //jtp.setSelectedIndex(index);
                jtp.setEnabledAt(index, true);
                //SetObjects.jtp.setSelectedIndex(index);
                //SetObjects.jtp.setEnabledAt(index, true);
            }[/b]
            if (e.getActionCommand().equals("actionsRemove")) {
                //enable menu items
                CreateInnerFrameMen..............................

output and error

CLASS 
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
 xxxxxxxxxxxxxxxxxxxxxxxxxx: 
CheckNewUser(String searchField) : false: bNewUser : returns :
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
        [b]at view.menus.innerframe.admin.JMenuControlAdmin.controlJMenuItems(JMenuControlAdmin.java:126)[/b]
        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)
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.