1 package com.ca.commons.cbutil; 2 3 import javax.swing.*; 4 5 6 15 16 public class CBSingleSelectionModel extends DefaultListSelectionModel 17 { 18 JList list = null; 19 20 public CBSingleSelectionModel(JList list) 21 { 22 this.list = list; 23 setSelectionMode(SINGLE_SELECTION); 24 } 25 26 public void setSelectionInterval(int index0, int index1) 27 { 28 int oldIndex = getMinSelectionIndex(); 29 super.setSelectionInterval(index0, index1); 30 int newIndex = getMinSelectionIndex(); 31 32 if (oldIndex != newIndex) 33 { 34 updateSingleSelection(oldIndex, newIndex); 35 } 36 } 37 38 public void updateSingleSelection(int oldIndex, int newIndex) 39 { 40 list.ensureIndexIsVisible(newIndex); 41 } 42 } 43 | Popular Tags |