Win a copy of Java Database Connections & Transactions (e-book only) this week in the JDBC forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

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

 
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
 
Sheriff
Posts: 21747
102
Chrome Eclipse IDE Java Spring Ubuntu VI Editor 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
 
Lasagna is spaghetti flvored cake. Just like this tiny ad:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!