The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

Re: How to generate an ActionEvent progrematically

You could manually create an action event and then call the actionPerformed method, or alternatively create the action event and then call a method inside JComboBox to fire the event (I'm not sure what the name is, look it up with google, I think it's something like "dispatchEvent", or "fireEvent")

Re: How to generate an ActionEvent progrematically

If you want to immediately jump to the code in the listener, rather than trying to create new ActionEvent's and dispatching them, perhaps you could strip out the code from within the actionPerformed method of the listener and encapsulate it in an object or method, in which case you can call that code from either context.

Re: How to generate an ActionEvent progrematically

In a part of my program, I want to execute a procedure which is done normally after one of the items of JComboBox is selected manually. suppose that when I select the first Item of a JComboBox it opens a JEditorPane and displays something. In another part of my program I change the content of this JEditorPane.After changing the content I want the JEditorPane to be refreshed and show new content. so I need the procedure which was done by selecting the first Item of JComboBox previously, executes this time automatically (progremmaticaly) and not by selecting that option manually

Re: How to generate an ActionEvent progrematically

Why not just make the code in your combo box ActionListener.actionPerformed method available to the other part of the program? For example make it a method in a class that both parts of the program can access, or pass the action code to the other part of the program, for example, something like this: