Question regarding JButton .setVisible() and .setEnabled()

Good morning,

First of all hi, I am a noob to the forum and novice to Java. I know the basics.

I am creating an applet that helps novice guitarists learn the electric guitar. The basic idea is the user presses a combination of buttons representing notes on the guitar, and then the program calculates the tablature and plays back a slide show of the notes being played along with the corresponding AudioClips. And it pretty much works.

However, I do have problems with JButtons not disappearing or blanking out when I want them to. Sometimes they do, sometimes they don't, and it seems completely random. They are, however, always unselectable so I presume its something to do with refreshing the graphics. Does anyone know what I am doing wrong? Heres a snippet of the context in which I am using .setEnabled():

- Apologies for the coarse naming of some of the variables, this is where I got frustrated.
- The code is lengthy, is not OO, is ugly and needs refactoring. Sorry.

I would really appreciate and pointers that can be given!

Regards,

J

EDIT: I have attached another file that is much shorter and more basic (but still part of my applet) and has the same problem. The 'pause' and 'stop' buttons start off as .setEnabled(false) and when either of the play buttons are pressed they are set to true. However, they appear grayed out UNTIL the mouse cursor passes over them?!

This applet is online if anyone wants to view, but I would rather not put the URL on a public forum just yet, so PM me if necessary.

FURTHER EDIT: Can't seem to attach another file, so here is the shorter code:

For changing the UI, you have to make sure that the code is executed by the event handling thread. This can be done using either SwingUtilities.invokeLater() or having the code in an event listener (e.g. using addActionListener()). Also, be sure to call repaint() if you change the appearance of something, and revalidate() if you change the contents of a container (add/remove components)