how to use JList and Un ArrayList java

0

I am trying to create a list of vehicles I made 4 classes the father class and the daughters that are aerial and maritime land.

what I do is something like that

public static ArrayList<Transportation> transportations = new ArrayList<Transportation>();

and I add data like that

Transportation overland = new Overland("1", "451fsfd4", "p0245", "serie 5", "2016", "4", "4 persons", 165000.00, 5, "Honda civic", 1);

Transportation overland1 = new Overland("2", "4444531s4", "oq45", "prueba", "2011", "4", "4 persons", 565000.00, 7, "bugati", 1);

Transportation Aerial = new Aerial("3", 2, 3, 2, 1000000.00, "aeroplano", 2, 4); 

Transportation Maritimo = new Maritimos("4", "serie 4", "BAVARIA", "30 personas", 3000000.00, "yate prueba", "lancha", 3, 1); 

transportations.add(overland); transportations.add(overland1); 

transportations.add(Aerial); transportations.add(Maritimo);

I try to insert them into a JList something like that

JList list= new JList();

list.setModel(transportations);

I also tried sending it to him

for (Transportation trasporte : trasportstions) {
  post.setModel(transporte);
}

I would really appreciate the help.

    
asked by Alejandro Pichola 27.10.2018 в 03:55
source

1 answer

1

You can use the JList -> JList(Object[]) constructor you just have to do this:

JList list = new JList(transportations.toArray());
    
answered by 27.10.2018 / 04:37
source