Getting the selected object position of a JComboBox?

JComboBox defines getSelectedIndex() The implementation is just to loop over the data model checking equality with getSelectedItem().

JComboBox defines getSelectedIndex(). The implementation is just to loop over the data model checking equality with getSelectedItem(). That doesn't make it up into ItemSelectable, but neither does the data model itself, so you may need to use the concrete class.

Didn't quite understood what that means. In the eclipse it gives me the option off add(Component comp, Index int). Can the component be a string from x position of the array?

– Lucky Jul 12 at 5:28 By "concrete class", I mean you may need to use JComboBox in your listener code instead of ItemSelectable. – Michael Brewer-Davis Jul 12 at 5:42 for JComboBox would be better look for ItemListener, +1 – mKorbel Jul 12 at 5:51 Ok, I got the idea and I successfully implemented it. Thanks – Lucky Jul 12 at 14:40.

Instead of storing items in a ComboBox and having to use the index to reference another array of values. Just store an object in the ComboBox that has a toString() output that matches your current displayed value and a direct reference to the object in the array. That way any object pulling the selected item or dealing with comobo box can just pull the value they need and not have to also "know" about this other array.

The problem with that method would be the repeated names(i think), that's why I needed the I position. Got it now. But I thank you for the insight.

– Lucky Jul 12 at 14:41 @Lucky, this would solve the repeat names issue because each position would have a different object with the correct value regardless of the description. – jzd Jul 12 at 16:07.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions