Hi
I have a JcomboBox. I want to display all the item id's in the jcombobox.For that I wrote a function selectId(). It is returning all the Id correctly.But it is not displaying in the Jcombobox.It is displaying something like this.[Ljava.lang.Object;@30d82d in the combobox. Can anybody tell me why it is like that.
the code is:-
public Object[] selectItemID(){
ArrayList itemNo = null;
try {
statement = dbConnection.prepareStatement("select ItemId from ItemDetails");
ResultSet itemNumberResult = statement.executeQuery();
itemNo = new ArrayList();
DbActivity dbconnection = new DbActivity();
Object[] result= dbconnection.selectItemID();
for(int i = 0; i < result.length; i++) {
itemno.addItem(result);
System.out.println(result[i]);
}
10-03-2005, 09:05 AM
sjalle
Hmmm ?
I've tried the same, stuffing and arrayList with strings, converting it to
an array and returning that array for storing in a comboBox, - and the string
values appear just as they were stored in the arraylist :confused:
Are you sure this code fragment produced the result you are saying ?
When a JComboBox or JList is displaying objects then the objects' toString() method is used, so, if there is no implementation of that
method in the displayed objects, then the objects' reference (address) is
displayed (the java.lang.Object implementation of toString()).
10-03-2005, 09:13 AM
daina
Hi
I got the answer
the code is
DbActivity dbconnection = new DbActivity();
Object[] result= dbconnection.selectItemID();
for(int i = 0; i < result.length; i++)
{
itemno.addItem(result[i]); <--------Give result[i]
}
itemno.addItemListener(this);
10-03-2005, 12:27 PM
sjalle
..that little bugger slipped my attention (must have new glasses).