Mega Code Archive

 
Categories / Java / Swing JFC
 

A spinner that rolls from the end of a list to beginning

import java.util.List; import javax.swing.SpinnerListModel; public class RolloverSpinnerListModel extends SpinnerListModel {   public RolloverSpinnerListModel(Object[] items) {     super(items);   }   public RolloverSpinnerListModel(List items) {     super(items);   }   public Object getNextValue() {     Object nv = super.getNextValue();     if (nv != null) {       return nv;     }     return getList().get(0);   }   public Object getPreviousValue() {     Object pv = super.getPreviousValue();     if (pv != null) {       return pv;     }     List l = getList();     return l.get(l.size() - 1);   } }