Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to add new tabs from JMenu

 
Med Shabe
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a JMenu class (GoofyMenuBar.java) and a JTabbedPane class (LoginTabbedPane.java) that I�m putting into a splitPane (SplitPane.java).

Clicking on the Go button opens a new tab. I need to invoke the same action from the menu but somehow I�m not making the connection between the components.

Regardless of the ugliness, how can I invoke a method on JTabbedPane from the JMenu, and later from the JToolBar. Apparently, simply instantiating the class does not do the trick.

Appreciate the input.


LoginTabbedPane


GoofyMenuBar.java


SplitPane
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you want item1 of the menu to create/add an info page?
(same as clickig the 'Go' button)

if so, follow the changes here, and you should get it to work OK

the main differences are the passing of the LoginTabbedPane reference to the
GoofyMenuBar class, and the creation of a separate method to create/add
the info page - this can then be called by both the Go button and the menu item

note: lots of 'comment-outs', just to get it to compile - I don't have
programix.* stuff, or FormLayout stuff. I put them all in one java file,
but you have 2 x main()

you will probably need to handle a second click on the menu item - do you
want a second info page created/added etc etc



 
Med Shabe
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Michael.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic