I've come across a problem where when I want to use the setText() method on a label, it won't change the label's text. I've searched for a long time, but couldn't find any solution. Here is a sample of the code:
class OptionsListener implements ItemListener{
public void itemStateChanged(ItemEvent e) {
if (optionsI1.isSelected()){
lesu1.setText("8:30");
}
}
}
I display all the components I use into another class, everything is displayed correctly.
I've tried simplifying the code by doing something like this:
class OptionsListener implements ItemListener{
public void itemStateChanged(ItemEvent e) {
if (optionsI1.isSelected()){
System.out.println("bla");
}
}
Which seems to work fine and display the message "bla". Anything I'm missing here?
The declaration of my elements (only showing the labels and menu's in the order I coded it):
// labels //
lesu1 = new JLabel("1");
lesu1.setBounds(8, 39, 20, 22);
lesu2 = new JLabel("2");
lesu2.setBounds(8, 69, 20, 22);
lesu3 = new JLabel("3");
lesu3.setBounds(8, 99, 20, 22);
lesu4 = new JLabel("4");
lesu4.setBounds(8, 129, 20, 22);
lesu5 = new JLabel("5");
lesu5.setBounds(8, 159, 20, 22);
lesu6 = new JLabel("6");
lesu6.setBounds(8, 189, 20, 22);
lesu7 = new JLabel("7");
lesu7.setBounds(8, 219, 20, 22);
lesu8 = new JLabel("8");
lesu8.setBounds(8, 249, 20, 22);
dag = new JLabel("07/08");
dag.setBounds(5, 15, 36, 13);
// menubar //
menu = new JMenuBar();
options = new JMenu("Opties");
optionsI1 = new JCheckBoxMenuItem("Weergeef de lesuren in uren");
optionsI1.addItemListener(new OptionsListener());
menu.add(options);
options.add(optionsI1);
This is the order I placed those components. I also added them to the panel in this order.