wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes Two ActionListeners 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 "Two ActionListeners" Watch "Two ActionListeners" New topic

Two ActionListeners

Jhon Calado

Joined: Jun 06, 2013
Posts: 9
Hey guys,

I'm having a little problem with a GUI :

I have a ComboBox and a Button("Submit");
I want to write the content of the ComboBox to a File when I hit submit;
I can do that with TextFields (a simple get.Text, BufferedWriter and an ActionListener for the Button);
To do it with ComboBox I need an extra ActionListener to "listen" to the SelectedItem in my ComboBox;
How do I pass the SelectedItem from the (ComboBox) ActionListener to the (Button) ActionListener so it can be written in my file?

I'm probably making other little mistakes but the two ActionListener(s) using the same variable -the item selected- is what's bothering me.
I tried to find solutions elsewhere but no luck.

I guess here I can't pass the SelectedItem to the other ActionListener as an argument and I must implement the ActionListener for the ComboBox,otherwise if I just do a simple combolist.getSelectedItem it returns null.

Thank you in advance.

Jhon Calado

Joined: Jun 06, 2013
Posts: 9
I get it now.Problem solved.
I agree. Here's the link: http://aspose.com/file-tools
subject: Two ActionListeners
Similar Threads
2D Array Help
JTabbed Pane: How to hide the frame containing the tabbed panes
Display Loop Results In TextArea Instead Of Command Window
Java not recognising SQL statements to retrieve data from database
parsing from JTextField to double