I am trying to permit the player to choose from predefined factions, but allow him to rename his own if it suits him. For this, I’m trying to use an editable JComboBox. However, the box refuses to be edited. That is, it comes up on the screen as it should, and I can select my hardcoded strings; but when I click on it to try editing, it doesn’t seem to gain the keyboard focus. Do I need to do anything special, other than call setEditable(true), to make it do so? Here’s my code so far :
constructor {
(...)
familyChoice = Family.getFamilyChoice();
familyChoice.setBounds(250, 50, 175, 30);
familyChoice.setVisible(false);
familyChoice.setEditable(true);
getLayeredPane().add(familyChoice, JLayeredPane.PALETTE_LAYER);
}
// In class Family :
public static JComboBox getFamilyChoice () {
String[] temp = new String[allFamilies.length];
for (int i = 0; i < temp.length; i++)
temp[i] = allFamilies[i].name;
return new JComboBox(temp);
}
I call setVisible(true) in actionPerformed, and it pops up just as it should. I am not overwriting any of the painting methods. Suggestions?
