| Author |
Can I make a JPanel perform an action?
|
Nick George
Ranch Hand
Joined: Apr 04, 2004
Posts: 815
|
|
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
|
I've heard it takes forever to grow a woman from the ground
|
 |
Craig Wood
Ranch Hand
Joined: Jan 14, 2004
Posts: 1535
|
|
|
How to Use Key Bindings
|
 |
Nick George
Ranch Hand
Joined: Apr 04, 2004
Posts: 815
|
|
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
Joined: Jan 14, 2004
Posts: 1535
|
|
|
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?
|
 |
learner
Greenhorn
Joined: Nov 03, 2005
Posts: 9
|
|
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
Joined: Apr 04, 2004
Posts: 815
|
|
|
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
Joined: Jan 14, 2004
Posts: 1535
|
|
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
Joined: Apr 04, 2004
Posts: 815
|
|
|
Thanks, I think that'll work.
|
 |
 |
|
|
subject: Can I make a JPanel perform an action?
|
|
|