• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

Can't get an ActionListener to change a JLabel text

 
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!

 
Bartender
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.
 
Marshal
Posts: 65425
248
  • 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
 
You guys wanna see my fabulous new place? Or do you wanna look at this tiny ad?
professionally read, modify and write PDF files from Java
https://products.aspose.com/pdf/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!