All Downloads are FREE. Search and download functionalities are using the official Maven repository.

de.invation.code.toval.graphic.component.EnumComboBox Maven / Gradle / Ivy

Go to download

TOVAL comprises a set of java classes for common programming issues. It includes utils for arrays, lists, sets and collections for convenient handling and modification, but also support for mathematic definitions concerning logic (clauses + resolution) together with some algorithms for permutations, powersets and resolution. Additionally it contains a number of types for multisets, matrices with object keys and much more.

The newest version!
package de.invation.code.toval.graphic.component;

import java.util.Arrays;

import javax.swing.DefaultComboBoxModel;
import javax.swing.JComboBox;

import de.invation.code.toval.validate.Validate;

public class EnumComboBox> extends JComboBox{

	private static final long serialVersionUID = -3998550187333465250L;

	public EnumComboBox(Class enumeration){
		this(enumeration, false);
	}
	
	public EnumComboBox(Class enumeration, boolean allowNull){
		Validate.notNull(enumeration);
		int padding = allowNull ? 1 : 0;
		Object[] objects = Arrays.copyOf(enumeration.getEnumConstants(), enumeration.getEnumConstants().length + padding);
		setModel(new DefaultComboBoxModel(objects));
	}

	@SuppressWarnings("unchecked")
	@Override
	public E getSelectedItem() {
		try{
			return (E) super.getSelectedItem();
		} catch(Exception e){
			return null;
		}
	}
	
	

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy