Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java

Antone Bagnall
Antone Bagnall
6,744 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.