Hello.
I created a JTabbedPane on a panel and put it on a JInternalFrame of a JDesktop in
SetObjects.java.

Why can't I get a tabbcount for it after running an AbstractAction?

reference JTabbedPane

reference JTabbedPane

M =(" --> in controlJMenuItems("+e.getActionCommand()+") var: e.getActionCommand() : xxxxxxxx<-- \n");
                 System.out.println(M);
                 jtp=SetObjects.getCurrentJTabbedPane();
[b]     error ----> int count =jtp.getTabCount();[/b]
                  System.out.println(C+M+AND+count+": c : \n");

reference JTabbedPane

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:128)
        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)

What exactly is the error message - or are we supposed to guess? ;-)

What exactly is the error message - or are we supposed to guess? ;-)

I don't know. The error message is what it says it is. It is supposed to sys out the number of tabs on a JTabbedPane that is created in SetObjects. Not sure how to generate a more specific error message than the one posted.
My guess is null pointer.

When I run the JDesktop it produces a JInternalFrame with a panel on it that holds a JTabbedPane with 11 tabs.

I use the menu on this Internal Frame. I click the MenuItem and it creates a notes JInternalFrame with a panel on it that hold a JTabbedPane with 2 tabs.

I go back to the first JInternalFrame and click a menuItem to navigate to tab 8 of 11 and
it is only sees the 2 tabbed pane. Using a abstactAction class I reference the first
JInternal frame, the panel and the JTabbedPane (this post show that the JTabbedPane is not being referenced at all.

Does your program throw an exception when you run it?
Do you catch the exception?
Do you print the entire exception message as in e.printStackTrace(); ?

The text in your original post is not a complete exception message; the stack is there but not the exception itself.

Does your program throw an exception when you run it?
Do you catch the exception?
Do you print the entire exception message as in e.printStackTrace(); ?

The text in your original post is not a complete exception message; the stack is there but not the exception itself.

I am not sure what exception to catch. I expected to have jtp as the TTabbedPane from another class but it is not there.

I'm sorry. I don't even know what that sentence is supposed to mean.

commented: You aren't alone in that. +14

I'm sorry. I don't even know what that sentence is supposed to mean.

When I run the JDesktop it produces a JInternalFrame with a panel on it that holds a JTabbedPane with 11 tabs.

I use the menu on this Internal Frame. I click the MenuItem and it creates a notes JInternalFrame with a panel on it that hold a JTabbedPane with 2 tabs.

I go back to the first JInternalFrame and click a menuItem to navigate to tab 8 of 11 and
it is only sees the 2 tabbed pane. Using a abstactAction class I reference the first
JInternal frame, the panel and the JTabbedPane (this post show that the JTabbedPane is not being referenced

There is no error I was asking how to reference the proper JTabbed pane as described in the first post
Thanks

OK, you have two tabbed panes and your code is referencing the wrong one?
If so, that sounds like some simple logic error (eg using the wrong name somewhere, or re-using the same variable incorrectly), but there's no way to check that without all the code.It really shouldn't be hard.

There is defiantly an error in logic because I think I am creating
and setting the component
and trying to reference them in another class

so how should I reference the JTabbedPane ?

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

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);
         [b]setCurrentContentPane(contentPane);[/b]
        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

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[i];
                    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);
           [b] setCurrentJTabbedPane(currentJTabbedPane);[/b]

        }

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

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 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_")) {[b]
            frame= SchoolJDesktopPane.getCurrentGuide();
            pane= SetObjects.getCurrentJTabbedPane();[/b]
            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);
[b]
                 
                 jtp=getPane();
                 jtp.setSelectedIndex(index);
[b]
[b]why isn't the JTabbedPane from when it was create?[/b]
                 
                  /*
                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)

Is there anyone that knows how to make a menu work with several Internalframes in a desktop?

Yes, there are many such people here.
But what you need is someone who can fix your logic error with a few hundred lines of code fragments with virtually zero useful comments stuffed full of calls to methods and variables whose definitions you have not published followed by a lengthy custom diagnostic message that presumably means something to you.

Where you mark the code you have jtp=getPane(); and you ask "why isn't the JTabbedPane from when it was create?" Allowing for English not being your first language, I guess you mean that jtp is not referring to the tabbed pane you expected it to refer to?
You have not posted the declaration(s) of jtp, and, even worse, you have not posted the definition of getPane(). It's impossible to diagnose like that.

Yes, there are many such people here.
But what you need is someone who can fix your logic error with a few hundred lines of code fragments with virtually zero useful comments stuffed full of calls to methods and variables whose definitions you have not published followed by a lengthy custom diagnostic message that presumably means something to you.

Where you mark the code you have jtp=getPane(); and you ask "why isn't the JTabbedPane from when it was create?" Allowing for English not being your first language, I guess you mean that jtp is not referring to the tabbed pane you expected it to refer to?
You have not posted the declaration(s) of jtp, and, even worse, you have not posted the definition of getPane(). It's impossible to diagnose like that.

unsolved:musicsys:

Hello

What is wrong with the logic behind creating a JTabbedPane and getting the tab count
of 11 then using a setter?

I try to reference the tabCount of the SetObjects.currentJTabbedPane and it throws
NullPointerException?

create

jtp.setSelectedIndex(0);

            int jtpCount=jtp.getTabCount();
             System.out.println(C+M+AND+jtpCount+": jtpCount of The JTabbedPane created: \n");

            setCurrentJTabbedPane(currentJTabbedPane);
            int currentCount=SetObjects.currentJTabbedPane.getTabCount();
             System.out.println(C+M+AND+currentCount+": currentCount for SetObjects.currentJTabbedPane.getTabCount() : \n");

setter

public static void setCurrentJTabbedPane(JTabbedPane currentJTabbedPane) {

          String M =(" --> in setCurrentJTabbedPane() var: <-- \n");
          System.out.println(M);

      
          SetObjects.currentJTabbedPane = currentJTabbedPane;
            System.out.println(C+M+AND+SetObjects.currentJTabbedPane.getTabCount()+": SetObjects.currentJTabbedPane.getTabCount() : \n");
    }

output

CLASS 
  SetObjects: 
  --> JTabbedPane obj() var: xxxxxxxxx : xxxxxxxx<-- 
 : 11: jtpCount of The JTabbedPane created: 

 --> in setCurrentJTabbedPane() var: <-- 

        Exception in thread "main" java.lang.NullPointerException
        at view.SetObjects.setCurrentJTabbedPane(SetObjects.java:385)
        at view.SetObjects.obj(SetObjects.java:217)
        at view.SchoolJDesktopPane.createInnerFrame(SchoolJDesktopPane.java:119)
        at view.SchoolJDesktopPane.<init>(SchoolJDesktopPane.java:97)
        at view.Main.createJDesktopPane(Main.java:60)
        at view.Main.main(Main.java:54)

The problem was extremly simple. Stupid mistake. I didn't have jtp passed to the setter works great. much thanks Kramerd for showing me
the concept of the AbstractAction.

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.