• 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

Can I make a JPanel perform an action?

 
Ranch Hand
Posts: 815
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
By adding an ActionListener to a button, we can make the button affect things it doesn't have privelage to talk to itself.

Is it possible to use a similar system with a JPanel and the container the JPanel is in? Have the container add an ActionListener to a JPanel, and then make the JPanel fire an action event?

Thanks,
Nick
 
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How to Use Key Bindings
 
Nick George
Ranch Hand
Posts: 815
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks.
Once I've added something to the action map, how can I fire it whenever I like? I don't want it to be a response to keyboard input.
 
Craig Wood
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There might be a lot of possibilities depending on what you are trying to do. Can you say some more about what you want to do?
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is it possible to use a similar system with a JPanel and the container the JPanel is in? Have the container add an ActionListener to a JPanel, and then make the JPanel fire an action event?

Ofcourse, you can make a JPanel listen to events. If you have a button and textarea in the JPanel, then whenever an event occurs in the text area or button, the same action takes place.
 
Nick George
Ranch Hand
Posts: 815
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My deal is, say I have 2 classes which extend JPanel in one big JPanel. I want to make it so that when JPanel A is modified it automatically updates JPanel B, but I'd rather not give JPanel A a pointer to JPanel B. My dream is that from the big JPanel I could add an action to A which updates B.
 
Craig Wood
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Two possibilities come to mind for this
1 — THE OBSERVER PATTERN
2 — a PropertyChangeListener which is discussed here: How to Write a Property Change Listener.
 
Nick George
Ranch Hand
Posts: 815
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, I think that'll work.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic