The Artima Developer Community
Sponsored Link

Java Answers Forum
arraylist

1 reply on 1 page. Most recent reply: Oct 23, 2002 6:03 AM by Parag Doshi

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
peter

Posts: 1
Nickname: peter12
Registered: Oct, 2002

arraylist Posted: Oct 22, 2002 2:35 AM
Reply to this message Reply
Advertisement
I have a method (getName) that returns an arraylist. Now i wanna put an element in a textarea, and that if you press a button you go to the next element (or the previous or last...).
I tried to work with an iterator for a combobox on the following manner
(getName returns an arraylist) and it works. But if I want to apply it to a textarea or a textfield (by replacing the addItem method by setText) it gives an error. Could anyone help me please.
I think i have to work with indexes or something, but since i am a beginner i don't know the code for this. Code would be helpful.

//for the combobox:
Data data= new Data();
ArrayList list1= data.getName();
Iterator iterator1= list1.iterator();
while (iterator1.hasNext()){
namecombobox.addItem(iterator1.next());
}

peter


Parag Doshi

Posts: 2
Nickname: parag
Registered: Oct, 2002

Re: arraylist Posted: Oct 23, 2002 6:03 AM
Reply to this message Reply
From what I can understand, the iterator.next() returns an Object and as addItem takes any Object type as a parameter, ur code used to work. The setText method could be taking a String as a parameter, so to make it work, u would have cast it to a String (assuming the arraylist has objects of type String). For eg.

comboBox.setText((String)i.next());

Flat View: This topic has 1 reply on 1 page
Topic: avi & Swing?? HELP!! Previous Topic   Next Topic Topic: Want to compile class in a different folder

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use