⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 e792. creating a spinnerlistmodel that loops through its values.txt

📁 这里面包含了一百多个JAVA源文件
💻 TXT
字号:
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);
        }
    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -