Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Implementing listeners to menu events

 
Steven Thomas
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a JDesktop --> with multiple JInternalFrames with tabbed panes (each with completely different data calendar, todo list, reminder, notes)
I have added a MenuBar to the main JFrame
One of the menu items is "Print"

When the user clicks Print from the menu I would like the "print function" of the active JPanel in the tabbed pane to act on the print command.

Not sure Java can do this is elegantly. Any help is appreciated.
 
Haina Minawa
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Steven Thomas wrote:

Not sure Java can do this is elegantly. Any help is appreciated.


Surely Java can do that. Take a look at: How to use menus
 
Rob Spoor
Sheriff
Pie
Posts: 20531
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Steven Thomas wrote:I have added a MenuBar to the main JFrame

Please tell me you meant JMenuBar instead of MenuBar... You shouldn't mix AWT components like MenuBar with Swing components like JFrame.

When the user clicks Print from the menu I would like the "print function" of the active JPanel in the tabbed pane to act on the print command.

JDesktopPane has method getSelectedFrame() which returns a reference to the currently active JInternalFrame. Use it to get its JTabbedPane, which has method getSelectedComponent() to get the currently active Component (the one you added with addTab or insertTab).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic