Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JMenuItem and ActionListener Issue

 
Ebiwari Williams
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48910
58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic