Here you can find the source of getTypedSelectedItemFromCombo(JComboBox
public static <E> E getTypedSelectedItemFromCombo(JComboBox<E> combo)
//package com.java2s; /*//from ww w . ja va2 s .c om * Copyright (c) 1998-2017 by Richard A. Wilkes. All rights reserved. * * This Source Code Form is subject to the terms of the Mozilla Public * License, version 2.0. If a copy of the MPL was not distributed with * this file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This Source Code Form is "Incompatible With Secondary Licenses", as * defined by the Mozilla Public License, version 2.0. */ import javax.swing.JComboBox; public class Main { /** * Since JComboBox.getSelectedItem() returns a plain Object, this allows us to get the * appropriate type of object instead. */ public static <E> E getTypedSelectedItemFromCombo(JComboBox<E> combo) { int index = combo.getSelectedIndex(); return index != -1 ? combo.getItemAt(index) : null; } }