• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JMenuItem and ActionListener Issue

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.





 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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())
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic