Joseph Posted April 5, 2014 Posted April 5, 2014 i have an Enum i would like to add into my gui combo box. im to lazy to retype them in a array string. i also no if i do this JComboBox<CraftingTable> craftingTableList = new JComboBox(CraftingTable.values()); i will get all my variable in my Enum in the combo box but the only problem is that they all in caps with and underscore and that looks unprofessional. i also no that you could add JComboBox<String> craftingTableList = new JComboBox(arrayString); and they will be in an the combo box. So i thought maybe if i create a String array method with the names of the Enum i could easly add them in my gui. my Method: public static String[] getAll() { List<String> list = new ArrayList<String>(); for (CraftingTable c: values()) if (c!=null) list.add(c.getName()); return (String[]) list.toArray(); } //in my enum this.name = super.name().charAt(0) + super.name().substring(1).toLowerCase().replace("_", " "); my gui: JComboBox<String> craftingTableList = new JComboBox(CraftingTable.getAll()); but it doesnt show anything in my gui. Any way i could do what i want.
Botre Posted April 5, 2014 Posted April 5, 2014 (edited) in your enum: @Override public String toString() { return "whatever you want" } Then .values will return "whatever you want". Edited April 5, 2014 by Botrepreneur
Baller Posted April 5, 2014 Posted April 5, 2014 (edited) 我不明白什么。请给我解释一下? Edited April 5, 2014 by Tigre
Joseph Posted April 5, 2014 Author Posted April 5, 2014 in your enum: @Override public String toString() { return "whatever you want" } Then .values will return "whatever you want". Just override the toString() thanks 我不明白什么。请给我解释一下? :p just gotta learn