aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes How do you program a Container to let it's content compontent to listen to one specific action? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How do you program a Container to let it Watch "How do you program a Container to let it New topic
Author

How do you program a Container to let it's content compontent to listen to one specific action?

Farhad Rahmati
Ranch Hand

Joined: Dec 16, 2010
Posts: 96
Hey Guys

If you have a JPanel and it contains many button may be 50 or 60 button. and you want to program the buttons to do the same function for example to show a JDialog box.


Thanks
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3361
    
    9
Hi Farhad,

Simply create an ActionListener instance and add that instance to every button using the addListener() method.

What is it that you're trying to do?
Farhad Rahmati
Ranch Hand

Joined: Dec 16, 2010
Posts: 96
Hi Stephan

I know, how to do as you suggested. for each button individually.

But I want to write only once for JPanel which is the container.

for example, I have 70 or 80 buttons in JPanel and it's hard to add that instance for each button individually.

then I want to do something with JPanel which contains all buttons. when you click on JPanel or it's content components, a JOptionPane show be show to tell you that this part of application is under construction. or this part of application is not working.

but as you suggested, I have tried that with Screen Keyboard.

actually I am looking for an alternative.

Thanks
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

You could make the JPanel implement an ActionListener and use it for all buttons and for the panel itself.


[My Blog]
All roads lead to JavaRanch
Farhad Rahmati
Ranch Hand

Joined: Dec 16, 2010
Posts: 96
Okay Thanks in advance
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How do you program a Container to let it's content compontent to listen to one specific action?
 
Similar Threads
Generating Mouseclick Programmatically
Listing a classes methods etc when no source
Java Install Question
Applets
displaying image over button