• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can't get an ActionListener to change a JLabel text

 
Patrick de Kruijf
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello there,

I have to make a GUI with four buttons (north, south, east, west) that changes the text of a JLabel in the middle of a JPanel. When I compile and press a button, nothing happens.

I tried a lot of changes in the code, I started with String variable as an argument for the JLabel JLabel(labelText) and found out later on that there is a setText() method that does this. All nice things I've learned, but the button still doesn't work. Every time I fire it up, the button layout stays the same, and clicking the buttons do not change the text. I tried declaring the inner classes public, but that doesn't do the trick, I thought this wasn't necessary anyway.

What am I doing wrong? Hope you can help me, thanks in advance!

 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are only invoking center.setText() add the WestListener.
 
Campbell Ritchie
Sheriff
Pie
Posts: 49367
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to another forum where we usually discuss such questions
 
Patrick de Kruijf
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much for your reply, and I appologize because I didn't show my appreciation earlier this week.

I had changed my code so many times that I was blind for this rather obvious mistake.

Thanks again, I am happy that the problem wasn't that big!

Hope to learn from you later,

Patrick
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic