Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
Nicholas Schembri
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Rob Spoor
Sheriff
Posts: 20893
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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>.
 
Nicholas Schembri
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!!
 
Nicholas Schembri
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK SOLVED
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!