Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

How to identify certain action from multiple sub-panels...

801416Dec 20 2010 — edited Dec 21 2010
Hello everyone,
I'm new to Swing... and I desperately need help...
I have ‘n’ numbers of JPanel. And each panel contains certain number of sub-panels. Those sub-panels have actionlisteners. How can I identify which sub-panel fire an action?
For example –
Panel_1 => sub_1, sub_2, sub_3
Panel_2 => sub_1, sub_2, sub_3
Panel_n => sub_1, sub_2, sub_3
Note that ‘n’ is unknown and main panels will be created dynamically. Now, if I attach actionListener with all of those sub_panels, how would I be able to figure out which sub_panel fires that action and thatsub-panel belongs to which main panel? In other words, if, sub_2 fires an action, how can I figure out that sub_2 belongs to which main panel?
Please help me.

Comments

StanislavL
Use your action event getSource() method/
801416
I know that I can use getSource() method to identify action event... but how can I identify the main panel it belongs to?
kleopatra-JavaNet
what's wrong with getSource().getParent() ? (apart from the missing type cast, obviously ;-)

Cheers
Jeanette
darrylburke
user1202074 wrote:
I have ‘n’ numbers of JPanel. And each panel contains certain number of sub-panels. Those sub-panels have actionlisteners.
:
Note that ‘n’ is unknown and main panels will be created dynamically. Now, if I attach actionListener with all of those sub_panels,
<tt>JPanel</tt>s can't have <tt>ActionListeners</tt>. What class of GUI component are you really talking about?

db
darrylburke
Cross posted
http://www.java-forums.org/awt-swing/36424-swing-how-indentify-certain-actions-sub-panels.html

Any more?

db
801416
when I said sub-panels, I meant Jtextfield, Jcombobox.
1 - 6
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Jan 18 2011
Added on Dec 20 2010
6 comments
85 views