Java tutorial
//package com.java2s; import javax.swing.JComboBox; public class Main { public static boolean isValidIndex(JComboBox<?> comboBox, int index) { if (comboBox == null) { throw new NullPointerException("comboBox == null"); } int itemCount = comboBox.getItemCount(); return index >= 0 && index < itemCount; } }