Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Java

Antone Bagnall
Antone Bagnall
6,741 Points

Java Swing: changing the text of a JLabel using an action listener

I have used an action listener on a JButton to change the text of a JLabel, although when the button is clicked nothing changes, any ideas what I'm doing wrong? The JLabel is called "crime description", here is the code in my action listener:

crimeDescription.setText(crime[randomInt].getCrimeName() + "\n" + crime[randomInt].getCrimeDescription());

crimeDescription.setVisible(true);

Demauri Portis
Demauri Portis
4,809 Points

I just have a suggestion, not saying it will fix the problem but have you tried using the repaint() method after all of your changes.