0

Hi Guys,

I posted earlier, and I figured it out after a few hours of playing around with it.

Now, a new question arises. Is it possible to get the input from a JTextField and add it into a JComboBox via an array?

The only thing stopping me from achieving this I think, is how to put the user input from the JTextField into an array. All I'd have to do after that is access that array though the JComboBox which I do understand.

There's no use for ActionListener here, right? Only for JButtons?

Thanks in advance!

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by javaAddict
0

It is better to get the text from the JTextField and add it directly to the JComboBox using the add method of the JComboBox class.
I order to get use the getSelectedItem method of the JComboBox class. It returns an object, so you will need to cast it to a String. Of course for this to work, all the items of the Combo Box need to be of type String.

Just in case, you used an other way to do it, and this one is more helpful.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.