File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Farhad Rahmati
Ranch Hand
Posts: 96
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 4818
34
Chrome Netbeans IDE Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 96
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could make the JPanel implement an ActionListener and use it for all buttons and for the panel itself.
 
Farhad Rahmati
Ranch Hand
Posts: 96
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay Thanks in advance
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic