Fetch array of strings from ArrayList for JList Java -


the task quite simple, faced 1 problem jlist component.

what need is. fetch data database, load string array, pack array arraylist (just because duno how many records have), return method arraylist. @ receiver side. have trouble, cant fetch string array arraylist can pass jlist.

here code.

arraylist<object> fetch = new arraylist<object>(); public string[] data =new string[10];     listmodel = new defaultlistmodel();           mylist = new jlist(listmodel);     //mylist = new jlist(data);     // works simple array of strings.     fetch=dao.loadpasswords();      //at point asks me cast object smth late cause null pointer exception.     mylist = new jlist(fetch.get(0)); 

and here loadpasswords();

public static arraylist<object> loadpasswords(){     dbconnect();     boolean unswer = false;     string[] result=null;     string query1 = "select * tblpasswordsstorage "             + "_user_id = ?";     string userid=personal_organizer.userprofile.getuserid();     arraylist<object> params = new arraylist<object>();     params.add(userid);     executequeryp(query1, params);     arraylist<object> fetched=null;     try {         if (rs.next()) {             unswer = true;             //personal_organizer.userprofile.setuserid(rs.getstring(1));             result[0]=rs.getstring(1);             result[1]=rs.getstring(2);             result[2]=rs.getstring(3);             result[3]=rs.getstring(4);             result[4]=rs.getstring(5);             result[5]=rs.getstring(6);             result[6]=rs.getstring(7);             result[7]=rs.getstring(8);             result[8]=rs.getstring(9);             result[9]=rs.getstring(10);             fetched.add(result);           }         if (unswer) {             while (rs.next()) {                 tools.print(rs.getstring(1));             }         }     } catch (sqlexception ex) {         joptionpane.showmessagedialog(null,                 "sql server connection issue.\n"                 + "please, check server address, user name , password.",                 "output",                 joptionpane.plain_message);     }     dbclose();     return fetched; } 

i tried use multidimensional array still jlist require single dimensional array.

either use defaultlistmodel , load strings using simple or for-each loop loops through arraylist, adding each string item in arraylist model, or create own listmodel class, 1 extends abstractlistmodel , uses arraylist data nucleus.

edit, since data held in arraylist of arrays, perhaps don't want display within arraylist after all, rather in jtable. here best bet create own tablemodel, 1 based off of abstracttablemodel , uses arraylist data nucleus. also, perhaps better loading data array create custom class hold each row of data resultset.


you state:

my problem load jlist. idea display application/website name in list, when click on it, full data contains in array. that's why put fetch.get(0)...because. need @ least something.

then

  • create custom class hold each row of data.
  • create items of class each row of resultset
  • fill defaultlistmodel items of class
  • give jlist custom listcellrenderer, 1 display's application/website name
  • then can display name , still have each list item hold pertinent information needs.

Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -