3
I wonder if someone could help me.
I’m trying to add items to a JComboBox
:
Pessoa carlos = new Pessoa(12, "Carlos" , 0.0f);
jComboBoxF.addItem(carlos.getNome());
Pessoa maria = new Pessoa(23, "Maria" ,0.0f);
jComboBoxF.addItem(maria.getNome());
In this case the JComboBox
is in the index "0" as the value "Carlos", and in the index "1" with the value Maria.
What I would like to know is whether adding the name was also possible to add the index, in order to be in this case with two identifiers 12 and 23, 12 for the value Carlos and 23 for the value Maria.
In other words I want to use the People id’s as the JComboBox
.
What I want with this is to use the index of JComboBox
to identify the Person in question, since the index of the combo in this way would be the Person’s own ID.
Will Carlos always be the thirteenth item of Jcombobox? Will Mary always be the twenty-fourth in the list? Or does the list have only these elements even?
– Victor Stafusa
In this case Jcombobox would only have two elements, Carlos and Maria. Your Index are 0 and 1 and I would like to be able to choose when inserting for example 12 and 23.
– André Pinto
So it seems to me that you don’t understand what the index of
JComboBox
I mean. It’s like an array, index 0 is the first item, index 1 is the second item, index 2 is the third item... And that’s not going to work if you want to have just two items with Dexe 12 and 23. I believe that what you really want is to retrieve that number that’s inside the person’s object, which is exactly what I showed you with my answer, because by what you describe their position and order inJComboBox
is not relevant to you, only the number you have associated with each Person is.– Victor Stafusa
I know how the index works and what its importance, was in doubt is if there would be any way to manipulate the index and we have come to the conclusion that not. The problem is solved by placing the object in Jcombobox and not just the name in order to access all attributes of the object. Thank you very much, problem solved.
– André Pinto