Jcombobox value


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: Jcombobox value

  1. #1
    Join Date
    Sep 2005
    Posts
    22

    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]);
    }

  2. #2
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    1,560

    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

  3. #3
    Join Date
    Sep 2005
    Posts
    22
    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);

  4. #4
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    1,560
    ..that little bugger slipped my attention (must have new glasses).
    eschew obfuscation

Similar Threads

  1. Display Value in JcomboBox
    By daina in forum Java
    Replies: 7
    Last Post: 10-10-2007, 08:21 PM
  2. JComboBox Problem
    By JavaMixin in forum Java
    Replies: 3
    Last Post: 09-02-2005, 01:59 AM
  3. Problem with JComboBox in JApplet
    By donraja_ht in forum Java
    Replies: 3
    Last Post: 03-30-2005, 01:43 AM
  4. Replies: 1
    Last Post: 08-01-2002, 10:48 AM
  5. problem with JCombobox
    By Satish in forum Java
    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
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center