Results 1 to 13 of 13
Thread: [SOLVED] ArrayList to listbox
- 11-30-2008, 03:09 AM #1
Member
- Join Date
- Nov 2008
- Posts
- 11
- Rep Power
- 0
[SOLVED] ArrayList to listbox
I have an arraylist (of strings) that I want to transfer into the elements of a listbox. I cant seem to figure out how to do this. I am using netbeans and didnt create the listbox myself.
Java Code:ArrayList arr = new ArrayList(); // populate arraylist with strings listBox.SetListData(arr); // Wont work listBox.SetListData(arr.ToString()); // Wont work either
-
sorry, but what is a listBox?
- 11-30-2008, 04:25 AM #3
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
You cannot add ArrayList into a list box, only Object[]. So you have to convert the ArrayList into Object[]
See what happen on the above line of code.Java Code:listBox.setListData(arr.toArray());
- 11-30-2008, 04:30 AM #4
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
- 11-30-2008, 04:31 AM #5
Member
- Join Date
- Nov 2008
- Posts
- 11
- Rep Power
- 0
- 11-30-2008, 04:33 AM #6
Member
- Join Date
- Nov 2008
- Posts
- 11
- Rep Power
- 0
- 11-30-2008, 04:36 AM #7
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
- 11-30-2008, 04:41 AM #8
Member
- Join Date
- Nov 2008
- Posts
- 11
- Rep Power
- 0
Here is my code...
Is it the error I mentioned above.Java Code:private void GetEntryList() { int ch; Dir = "H:\\Entries\\All.txt"; FileReader fReader = null; String Title = ""; ArrayList<String> arrEntries = new ArrayList<String>(); try { fReader = new FileReader(Dir); } catch (FileNotFoundException e) {e.printStackTrace();} do { do { try { ch = fReader.read(); if ((char)ch == '~') { do { Title += (char)ch; ch = fReader.read(); } while ((char)ch != '{'); Title = Title.replace("~", ""); arrEntries.add(Title); Title = ""; } } catch(IOException e){e.printStackTrace();} } while(true); } while(true); lstEntries.SetListData(arrEntries.toArray()); // <--- Error Here }
If this should work then maybe its a problem in NetBeans (v6.5).
EDIT: I know they are infinite loops... This method is in progress.Last edited by DanielS; 11-30-2008 at 04:43 AM.
- 11-30-2008, 04:44 AM #9
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Can you show up the declaration of lstEntries?
I don't think this is an issue on NetBeans 6.5. I'm working on that version too, but no issues at all.
- 11-30-2008, 04:46 AM #10
Member
- Join Date
- Nov 2008
- Posts
- 11
- Rep Power
- 0
- 11-30-2008, 06:23 AM #11
Java is case sensitive. Method names, by convention, start with a lowercase letter.
ergo, JList doesn't have a method SetListData.
db
- 11-30-2008, 06:27 AM #12
Member
- Join Date
- Nov 2008
- Posts
- 11
- Rep Power
- 0
- 12-01-2008, 03:50 AM #13
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Oh, I didn't notice that in your code segment.
Similar Threads
-
To highlight multiple selected values in listbox
By swapnanair in forum JavaServer Pages (JSP) and JSTLReplies: 1Last Post: 05-06-2008, 11:17 AM -
Java Project Trouble: Searching one ArrayList with another ArrayList
By BC2210 in forum New To JavaReplies: 2Last Post: 04-21-2008, 11:43 AM -
Listbox Add/Delete
By Rageagainst20 in forum New To JavaReplies: 2Last Post: 04-16-2008, 04:49 PM -
ArrayList
By kizilbas1 in forum New To JavaReplies: 1Last Post: 01-12-2008, 08:48 PM -
ArrayList
By kizilbas1 in forum New To JavaReplies: 11Last Post: 12-05-2007, 07:30 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks