zoukankan      html  css  js  c++  java
  • e792. 建立一个包括所有数据的SpinnerListModel

    By default, if the user is browsing the values in a SpinnerListModel, the iteration stops when either end is reached. This example demonstrates a subclass that allows the user to continuously loop through the values.

        SpinnerCircularListModel listModel = new SpinnerCircularListModel(
            new String[]{"red", "green", "blue"});
        JSpinner spinner = new JSpinner(listModel);
        
        public class SpinnerCircularListModel extends SpinnerListModel {
            public SpinnerCircularListModel(Object[] items) {
                super(items);
            }
        
            // Returns the next value. If the current value is at the end
            // of the list, returns the first value.
            // There must be at least one item in the list.
            public Object getNextValue() {
                java.util.List list = getList();
                int index = list.indexOf(getValue());
        
                index = (index >= list.size()-1) ? 0 : index+1;
                return list.get(index);
            }
        
            // Returns the previous value. If the current value is at the
            // start of the list, returns the last value.
            // There must be at least one item in the list.
            public Object getPreviousValue() {
                java.util.List list = getList();
                int index = list.indexOf(getValue());
        
                index = (index <= 0) ? list.size()-1 : index-1;
                return list.get(index);
            }
        }
    
    Related Examples
  • 相关阅读:
    第03次作业-栈和队列
    第02次作业-线性表
    Data-Structure01-绪论
    c语言第二次实验报告
    C语言第一次实验报告
    KD-tree讲解
    AAAA、
    清北学堂 day one
    生长,开始记录!
    Linux命令(待完善)
  • 原文地址:https://www.cnblogs.com/borter/p/9596248.html
Copyright © 2011-2022 走看看