I am back with another problem :(
Let me show you guys the code:
JCheckBox pPec = new JCheckBox("Potion Effect");
pPec.setBounds(new Rectangle(50, 270, 140, 30));
pPec.setFont(fDisp);
List<String> pPeLl = new ArrayList<String>();
for (DPE dpe : DPE.values()){
pPeLl.add(dpe.toString());
}
String[] pPeL = pPeLl.toString().replace("[", "").replace("]", "").split(", ");
JComboBox<String> pPeE = new JComboBox<String>(pPeL);
pPeE.setBounds(new Rectangle(175, 270, 150, 30));
List<String> pPeNLl = new ArrayList<String>();
for (int i = 1; i <= 255; i++){
pPeNLl.add(Integer.toString(i));
}
String[] pPeNL = pPeNLl.toString().replace("[", "").replace("]", "").split(", ");
JComboBox<String> pPeN = new JComboBox<String>(pPeNL);
pPeN.setBounds(new Rectangle(175, 300, 73, 30));
JTextField pPeT = new JTextField();
((AbstractDocument)pPeT.getDocument()).setDocumentFilter(new NumberFilter());
pPeT.setBounds(new Rectangle(175+73+4, 300, 73, 30));
if (file.exists()){
for (String s : DFileLoader.getMethod(pathToSaveAs)){
if (s.startsWith("playerPotionEffect%%@@")){
pPec.setSelected(true);
potionEffect = true;
break;
}else{
pPeN.setEnabled(false);
pPeT.setEnabled(false);
pPeE.setEnabled(false);
potionEffect = false;
}
}
if (DFileLoader.getMethod(pathToSaveAs).size() <= 0){
pPeN.setEnabled(false);
pPeT.setEnabled(false);
pPeE.setEnabled(false);
potionEffect = false;
}
}else{
pPeN.setEnabled(false);
pPeT.setEnabled(false);
pPeE.setEnabled(false);
potionEffect = false;
}
pPec.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
if (pPec.isSelected()){
pPeE.setEnabled(true);
pPeN.setEnabled(true);
pPeT.setEnabled(true);
}else if (!pPec.isSelected()){
pPeE.setEnabled(false);
pPeN.setEnabled(false);
pPeT.setEnabled(false);
}
if (pPec.isSelected()) potionEffect = true;
else potionEffect = false;
}
});
pane.add(pPec);
if (file.exists()){
for (String s : DFileLoader.getMethod(pathToSaveAs)){
if (s.startsWith("playerPotionEffect%%@@")){
String[] d = s.split("%%@@");
String text;
if (d.length <= 1) text = "";
else text = d[3];
pPeE.setSelectedItem(d[1]);
pPeN.setSelectedItem(d[2]);
pPeT.setText(text);
}
}
}
pane.add(pPeN);
pane.add(pPeT);
pane.add(pPeE);
The DFileLoader.getMethod(String) returns a String List
What I am trying to do is that it loads the information from a file, and if the file starts with "playerPotionEffect%%@@" (as shown after file.exists()), it sets the checkbox as selected. If not, it doesn't select it and it disables the other components shown in this piece of code. The checkbox selection works fine, it's just when I load the file, the 2 JComboBoxes and the JTextField are disabled, even though I want them to be enabled.
Can anyone help me? It might be really obvious where the problem is, and that I just haven't noticed. I have tried moving code around, but it still doesn't work.
the "pane" is a Container for the JFrame's content pane.
Also, I have it set to as you click on the checkbox, it enables and disables the other components. This works, and if I turned the checkbox off and on again, the components would be enabled. However, I just want it so that it is enabled on load when the box is checked.