|
A spinner that rolls from the end of a list to beginning |
|
|
This Java Swing tip illustrates a spinner that rolls from the end
of a list to beginning. This tip describes a custom spinner model
that rolls over the end of a list back to the beginning (or vice
versa).
import javax.swing.*;
import java.util.List;
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);
}
}
|
Related Tips
|
Page 1 of 0 ( 0 comments )
You can share your information about this topic using the form below!
Please do not post your questions with this form! Thanks.