Forums Register Login

populate a JList from a method in another Class (String[])

+Pie Number of slices to send: Send
I am sure that for many of you this is an easy question.

However I would like some help. I have a JList in the GUI class:

Object[] data = { "Emp1", "Emp2", "Emp3", "Emp4", "Emp5" };


JList empList = new JList(data);
empLis.setFixedCellWidth(400);


At the moment the data for the JList is populated from the same class as shown above.... However I have a method in the main class and I would like to populate my JList from it:

Main Class:

public String[] getAllPeople(){

}

I appreciate you help.

Thanks
+Pie Number of slices to send: Send
A String[] is an Object[], so you can use the return value of that method to create the JList.

You should know however that since Java 7 JList is made generic, so you can use a JList<String>.
+Pie Number of slices to send: Send
 

Rob Spoor wrote:A String[] is an Object[], so you can use the return value of that method to create the JList.

You should know however that since Java 7 JList is made generic, so you can use a JList<String>.



Thanks for your reply

Would it be possible to explain more how i can use the return value of the method: public String[] getAllPeople()

THANKS!!
+Pie Number of slices to send: Send
OK SOLVED
Gravity is a harsh mistress. But this tiny ad is pretty easy to deal with:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 789 times.
Similar Threads
Conversion of list contains Employee object
Need a query (will subquery and count work?)
Need help: Best possible result after comparing objects
Populating a list of Objects in Struts2
equals() and hashCode()
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 22:57:41.