aspose file tools*
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
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: 39784
    
  28
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JMenuItem and ActionListener Issue