This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes JMenuItem and ActionListener Issue Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JMenuItem and ActionListener Issue" Watch "JMenuItem and ActionListener Issue" New topic
Author

JMenuItem and ActionListener Issue

Ebiwari Williams
Greenhorn

Joined: Jul 26, 2011
Posts: 1
please help: I have two menuitem in in my JFrame.. nodeGraph and nodeCalculator each of this menu item when click is suppose to validate a new JPanel on the JFrame.. But only one of the JPanel display on the JFrame.





Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
the default layoutManager for JFrame is BorderLayout.
BorderLayout only allows one Component in an area (can be nested components).

when you have
add(new NodeCalculator());

this adds it to the default position (CENTER), then when you have this
add(new Node());

it also adds to CENTER, knocking out whatever else is there.

use a JPanel (with appropriate layoutManager), add the panel to the frame,
then add the 'nodes' to the panel (with revalidate()/repaint())
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38036
    
  22
Welcome to the Ranch

Make sure you are adding the right thing when you click that button. Adding another calculator seems peculiar to me, but you might have more information that it is all right.
I shall move this discussion to our GUIs forum.
 
jQuery in Action, 2nd edition
 
subject: JMenuItem and ActionListener Issue
 
Similar Threads
Making JTabbed Pane visible???
How to disable Menubar
How can I add another text box under this layout?
JMenu problem
help with GUI practice