Created
September 22, 2009 09:15
-
-
Save mhansen/190942 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** Define enum class that will popuplate your combo box */ | |
public enum E_ComboBoxEnum { | |
Item1("Item 1"), | |
Item2("Item 2"), | |
Item3("Item 3"); | |
private final String _displayName; | |
/** constructor */ | |
E_ComboBoxEnum(final String displayName) { | |
_displayName = displayName; | |
} | |
/** overrides method toString() in java.lang.Enum class */ | |
public String toString(){ | |
return _displayName; | |
} | |
} // end enum E_ComboBoxEnum | |
/** whatever class contains the JComboBox object, could be JFrame, JDialog, etc */ | |
public class ComboBoxGUI extends javax.swing.JDialog { | |
private javax.swing.JComboBox _myComboBox; | |
public void createComboBox(){ | |
_myComboBox = new javax.swing.JComboBox(); | |
/** model is set to be a new instance of DefaultComboBoxModel. this model | |
is initialized with an array of all possible values of E_ExpirationDateIntervals */ | |
_myComboBox.setModel(new javax.swing.DefaultComboBoxModel(E_ExpirationDateIntervals.values())); | |
} | |
/** the combo box will now display the Strings defined in the E_ComboBoxEnum class, in the order that they were defined. */ | |
/** _myComboBox.getSelectedItem() will return an E_ComboBoxEnum object (well technically a generic object that can be cast into an E_ComboBoxEnum object) */ | |
} // end class ComboBoxGUI |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment