I am trying to update an empty Jlabel every time I click the 'Load' Jbutton. I've added an actionlistener to the Jbutton, but for some reason the label just doesn't update or make any text appear with the setText(String) method.
JLabel stupidLabel = new JLabel();
stupidLabel.setForeground(SystemColor.infoText);
stupidLabel.setFont(new Font("Arial", Font.PLAIN, 11));
stupidLabel.setBounds(71, 46, 167, 14);
panel.add(stupidLabel);'
JButton load = new JButton("Load");
load.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
stupidLabel.setText("Update please");
}
});
load.setFont(new Font("Arial", Font.PLAIN, 11));
load.setBounds(189, 92, 89, 22);
contentPane.add(load);
Doesn't seem to work.
What seems to be the problem? Is there a way to make the label update automatically every second or so, effectively removing the need for a button altogether?