Here you can find the source of loadStaticItems(JComboBox target, Class source, Class> limit, String defaultItem)
@SuppressWarnings("unchecked") public static <A, B> void loadStaticItems(JComboBox<B> target, Class<A> source, Class<?> limit, String defaultItem)
//package com.java2s; //License from project: Open Source License import java.lang.reflect.Field; import javax.swing.JComboBox; public class Main { @SuppressWarnings("unchecked") public static <A, B> void loadStaticItems(JComboBox<B> target, Class<A> source, Class<?> limit, String defaultItem) { Field[] fields = source.getFields(); for (Field f : fields) { try { if (!java.lang.reflect.Modifier.isStatic(f.getModifiers())) { continue; }//from w ww. j ava 2 s .c o m Object v = f.get(null); if (v == null) { continue; } if (limit.isInstance(v)) { target.addItem((B) v); } } catch (IllegalAccessException | IllegalArgumentException | SecurityException e) { System.err.println("Error intializing GUI:" + f.getName()); e.printStackTrace(); } } for (int i = 0; i < target.getItemCount(); i++) { B item = target.getItemAt(i); if (item.toString().equals(defaultItem)) { target.setSelectedIndex(i); break; } } } }