-
Jcombobox value
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();
while(itemNumberResult.next())
{
String item = itemNumberResult.getString(1);
itemNo.add(item);
System.out.println("itemNo " +item);
}
} catch (SQLException e) {
e.printStackTrace();
}
return itemNo.toArray();
}
itemno=new JComboBox( );
DbActivity dbconnection = new DbActivity();
Object[] result= dbconnection.selectItemID();
for(int i = 0; i < result.length; i++) {
itemno.addItem(result);
System.out.println(result[i]);
}
-
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 
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()).
eschew obfuscation
-
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);
-
..that little bugger slipped my attention (must have new glasses).
eschew obfuscation
Similar Threads
-
Replies: 7
Last Post: 10-10-2007, 08:21 PM
-
By JavaMixin in forum Java
Replies: 3
Last Post: 09-02-2005, 01:59 AM
-
By donraja_ht in forum Java
Replies: 3
Last Post: 03-30-2005, 01:43 AM
-
Replies: 1
Last Post: 08-01-2002, 10:48 AM
-
Replies: 0
Last Post: 01-23-2002, 09:13 AM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks