Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package modelos; import java.util.ArrayList; import javax.swing.AbstractListModel; import javax.swing.ComboBoxModel; import org.apache.commons.lang3.StringUtils; /** * * @author Administrador */ public class CustomListModelCopias extends AbstractListModel implements ComboBoxModel { private ArrayList<Copias> lista = new ArrayList<>(); @Override public int getSize() { return lista.size(); } @Override public Object getElementAt(int index) { Copias p = lista.get(index); return "Cdigo copia: " + StringUtils.leftPad(String.valueOf(p.getNumeroSerie()), 13, '0') + " Titulo: " + StringUtils.rightPad(p.getTitulo(), 50, ' '); } /** * * @param p */ public void addLibro(Copias p) { lista.add(p); this.fireIntervalAdded(this, getSize(), getSize() + 1); } /** * * @param index0 */ public void eliminarLibro(int index0) { lista.remove(index0); this.fireIntervalRemoved(index0, getSize(), getSize() + 1); } /** * * @param index * @return */ public Copias getLibro(int index) { return lista.get(index); } /** * * @return */ public ArrayList<Copias> getLista() { return lista; } /** * */ public void removeAll() { lista.clear(); this.fireIntervalRemoved(0, getSize(), getSize()); } String selection = null; public void setSelectedItem(Object anItem) { selection = (String) anItem; // to select and register an } // item from the pull-down list // Methods implemented from the interface ComboBoxModel public Object getSelectedItem() { return selection; // to add the selection to the combo box } }