File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Can't get an ActionListener to change a JLabel text Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Can Watch "Can New topic
Author

Can't get an ActionListener to change a JLabel text

Patrick de Kruijf
Ranch Hand

Joined: Mar 02, 2010
Posts: 63
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!



------------------8<------------------
please cut here
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

You are only invoking center.setText() add the WestListener.


"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38007
    
  22
Moving to another forum where we usually discuss such questions
Patrick de Kruijf
Ranch Hand

Joined: Mar 02, 2010
Posts: 63
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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Can't get an ActionListener to change a JLabel text
 
Similar Threads
sharing Panel between frames
NullPointerException received trying to change the button label
Simple side-by-side layout manager?
please can someone help me password my Java program!
How can I diplay and Applet on a swing application?